1

我在 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 =>”,以便在static_pages_spec.rb. 故障排除时,我在两个“文本”版本之间切换并得到相同的结果。

关于我应该寻找什么来解决错误的任何建议?另外,我不确定如何阅读错误消息,即错误的第一部分是否显示正确的方法,反之亦然?

谢谢!

4

1 回答 1

1

您的提供线上似乎有不必要的空间。它应该是

<% provide(:title, 'Contact') %>

不是

<% provide (:title, 'Contact') %>
于 2012-12-21T14:25:06.130 回答