2013-06-13 3 views
0

나는 Ruby on Rails 2nd Ed., Hartl. 3.3.3 절에서 일부 내장 된 Ruby로 정적 텍스트를 제거한 후 내 테스트가 실패했습니다. 이 테스트는 이전에는 문제가 없었습니다. 콘솔Ruby on Rails 임베디드 루비 임베디드 오류

C:\Sites\rails_projects\sample_app>bundle exec rspec   spec/requests/static_pages_spec.rb 
    ?[31mF?[0m?[31mF?[0m?[32m.?[0m?[32m.?[0m?[32m.?[0m?[32m.?[0m 

    Failures: 

     1) Home pages Home page should have the h1 'Sample App' 
     ?[31mFailure/Error:?[0m ?[31mvisit '/static_pages/home'?[0m 
     ?[31mActionView::Template::Error:?[0m 
      ?  [31mC:/Sites/rails_projects/sample_app/app/views/static_pages/home.html.erb:1: syntax   error, 
    unexpected ',', expecting ')'?[0m 
      ?[31m...putBuffer.new; provide (:title, ' Home') ?[0m 
      ?[31m...        ^?[0m 
      ?  [31mC:/Sites/rails_projects/sample_app/app/views/static_pages/home.html.erb:1: syntax   error, 
    unexpected ')', expecting keyword_end?[0m 
      ?[31m....new; provide (:title, ' Home') ?[0m 
      ?[31m...        ^?[0m 
    ?[36m  # <internal:prelude>:10:in `synchronize'?[0m 
    ?[36m  # ./spec/requests/static_pages_spec.rb:7:in `block (3 levels) in <top   (required)>'?[0m 

     2) Home pages Home page should have the title 'Home' 
     ?[31mFailure/Error:?[0m ?[31mvisit '/static_pages/home'?[0m 
     ?[31mActionView::Template::Error:?[0m 
      ?  [31mC:/Sites/rails_projects/sample_app/app/views/static_pages/home.html.erb:1: syntax   error, 
    unexpected ',', expecting ')'?[0m 
      ?[31m...putBuffer.new; provide (:title, ' Home') ?[0m 
      ?[31m...        ^?[0m 
      ?  [31mC:/Sites/rails_projects/sample_app/app/views/static_pages/home.html.erb:1: syntax   error, 
    unexpected ')', expecting keyword_end?[0m 
      ?[31m....new; provide (:title, ' Home') ?[0m 
      ?[31m...        ^?[0m 
    ?[36m  # <internal:prelude>:10:in `synchronize'?[0m 
    ?[36m  # ./spec/requests/static_pages_spec.rb:12:in `block (3 levels) in <top   (required)>'?[0m 

    Finished in 0.51562 seconds 
    ?[31m6 examples, 2 failures?[0m 

    Failed examples: 

    ?[31mrspec ./spec/requests/static_pages_spec.rb:6?[0m ?[36m# Home pages Home page   should have the h1 'Sample App'?[0m 
    ?[31mrspec ./spec/requests/static_pages_spec.rb:11?[0m ?[36m# Home pages Home page   should have the title 'Home'?[0m 

에서

이 RSpec에

require 'spec_helper' 

    describe "Home pages" do 

     describe "Home page" do 
     it "should have the h1 'Sample App'" do 
      visit '/static_pages/home' 
      page.should have_selector('h1', :text => 'Sample App') 
     end 

     it "should have the title 'Home'" do 
      visit '/static_pages/home' 
      page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample     App | Home") 
     end 
     end 
    end 

home.html.erb

<% provide (:title, 'Home') %> 
    <!DOCTYPE html> 
    <html> 
     <head> 
      <title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title> 
     </head> 
     <body> 
      <h1>Sample App</h1> 
      <p> 
      This is the home page for the 
      <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> 
      sample application. 
      </p> 
     </body> 
    </html> 

오류가 어떤 도움

답변

2

난 당신이 공백을 제거 할 필요가 있다고 생각합니다 감사합니다 전에는 그는 지금 작업

provide(:title, 'Home') 
+0

그것이어야한다

provide (:title, 'Home') 

을 괄호. 그것은 공백이었다. 감사. 나는 그것이 단순해야만한다는 것을 알고, 단지 그것을 볼 수 없었습니다. 잘 했어! – JanuskaE

+0

미래를위한 FYI처럼 Ruby는 괄호에 대해 약간 까다롭게 보일 수 있습니다. 괄호를 생략하면 공백을 남기고 (분명히), 메서드 호출과 괄호 사이에 공백을두면 혼란 스러울 수 있습니다. 이것은 모든 곳에서 적용되지 않으므로 일관성을 유지하고 괄호 앞에 공백을 두지 않는 것이 가장 좋습니다 – muttonlamb

관련 문제