我在Michael Hartl的RoR教程的第5.3节中,我正在添加一个联系页面。我跑了$ bundle exec rspec spec/requests/static_pages_spec.rb
。我无法弄清楚错误。我在spec / requests / static_pages_spec.rb中进行了更改,并为联系页面添加了适当的路由,操作并编辑了联系页面的视图。这是输出:
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'
在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 Happy App | Contact")
end
在RoR教程中,这是您在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
我在static_pages_spec.rb
中所做的唯一更改是(1)将“Sample App”设为“Happy App”,(2)使用“text:”代替“:text =&gt;”,以便static_pages_spec.rb
中的代码格式一致。在进行故障排除时,我在两个“文本”版本之间切换并获得相同的结果。
有关我应该寻找什么来解决错误的任何建议?另外,我不确定如何读取错误信息,即错误的第一部分是否显示正确的方法,反之亦然?
谢谢!
答案 0 :(得分:1)
您的提供线上似乎有不必要的空间。它应该是
<% provide(:title, 'Contact') %>
不
<% provide (:title, 'Contact') %>