0

我正在研究 Ruby on Rails 第二版,Hartl。在第 3.3.3 节中,我使用一些嵌入式 Ruby 删除了一些静态文本后,我的测试失败了。测试通过之前没有问题。

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

主页.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>

来自控制台的错误

    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

任何帮助表示赞赏

4

1 回答 1

2

我认为您需要在括号之前删除空格

provide (:title, 'Home')

应该

provide(:title, 'Home')
于 2013-06-13T01:50:57.750 回答