2012-12-21 19 views
1

我在Michael Hartl的RoR教程的第5.3节中添加联系人页面。我跑了$ bundle exec rspec spec/requests/static_pages_spec.rb。我无法弄清楚错误。我在spec/requests/static_pages_spec.rb中进行了更改,并为联系页面添加了适当的路由和操作,并编辑了联系页面的视图。这是输出:在第5章布局链接部分添加页面时出错(Michael Hartl)

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)将“示例应用程序”设置为“开心应用程序”并且(2)使用“text:”而不是“:text =>”,以使格式一致ghout代码static_pages_spec.rb。在排除故障时,我在两个“文本”版本之间切换并得到相同的结果。

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

谢谢!

+1

什么是你**的应用程序/视图/ static_pages/contact.html.erb **查看文件是什么样子?如错误状态,它看起来像你有一个语法错误。 –

+0

<%提供(:标题, '联系方式')%>

联系

\t联系Ruby on Rails的教程关于快乐应用在 \t contact page

LearningHowToCode

回答

1

看来你的提供线上有不必要的空间。它应该是

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

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

谢谢。我看了很久,甚至没有看到这个额外的空间。 – LearningHowToCode

+0

发生在我们身上:-) –

相关问题