I am in section 5.3 in Michael Hartl’s RoR tutorial, where I am adding a Contact Page. I ran $ bundle exec rspec spec/requests/static_pages_spec.rb. I cannot figure out the error. I made changes in spec/requests/static_pages_spec.rb, as well as added the appropriate route, action for the contact page and edited the view for the contact page. This is the output:
Failures:
1) Static Pages Contact page should have the h1 'Contact'
Failure/Error: visit '/static_pages/contact'
ActionView::Template::Error:
/Users/themaktravels/rails_projects/happy_app/app/views/static_pages/contact.html.erb:1: syntax error, unexpected ',', expecting ')'
...putBuffer.new; provide (:title, 'Contact')
... ^
/Users/themaktravels/rails_projects/happy_app/app/views/static_pages/contact.html.erb:1: syntax error, unexpected ')', expecting keyword_end
...ew; provide (:title, 'Contact')
... ^
# <internal:prelude>:10:in `synchronize'
# ./spec/requests/static_pages_spec.rb:56:in `block (3 levels) in <top (required)>'
2) Static Pages Contact page should have the title 'Contact'
Failure/Error: visit '/static_pages/contact'
ActionView::Template::Error:
/Users/themaktravels/rails_projects/happy_app/app/views/static_pages/contact.html.erb:1: syntax error, unexpected ',', expecting ')'
...putBuffer.new; provide (:title, 'Contact')
... ^
/Users/themaktravels/rails_projects/happy_app/app/views/static_pages/contact.html.erb:1: syntax error, unexpected ')', expecting keyword_end
...ew; provide (:title, 'Contact')
... ^
# <internal:prelude>:10:in `synchronize'
# ./spec/requests/static_pages_spec.rb:61:in `block (3 levels) in <top (required)>'
Finished in 0.53514 seconds
9 examples, 2 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:55 # Static Pages Contact page should have the h1 'Contact'
rspec ./spec/requests/static_pages_spec.rb:60 # Static Pages Contact page should have the title 'Contact'
In static_pages_spec.rb, I have following:
describe "Contact page" do
it "should have the h1 'Contact'" do
visit '/static_pages/contact'
page.should have_selector('h1', :text => 'Contact')
end
it "should have the title 'Contact'" do
visit '/static_pages/contact'
page.should have_selector('title',
:text => "Ruby on Rails Tutorial Happy App | Contact")
end
In the RoR tutorial, this is what you are instructed to have in static_pages_spec.rb:
describe "Contact page" do
it "should have the h1 'Contact'" do
visit '/static_pages/contact'
page.should have_selector('h1', text: 'Contact')
end
it "should have the title 'Contact'" do
visit '/static_pages/contact'
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App | Contact")
end
The only changes I made in static_pages_spec.rb were (1) make “Sample App” to “Happy App” and (2) “text:” was used instead of “:text =>”, so that the format was consistent throughout the code in static_pages_spec.rb. When troubleshooting, I switched between both “text” versions and got the same result.
Any suggestions on what I should be looking for to solve the error? Also, I am unsure of how to read the error message, i.e. does the first section of the error show the proper method or vice versa?
Thank you!
It seems you have an unnecessary space on your provide line. It should be
not