0

Michael Hartl の Ruby on Rails チュートリアルの第 5 章の演習に取り組んでいますが、理解できないテストの失敗が続いています。

私は click_link の問題に取り組んでおり、すべての大文字が一致し、他のすべてのファイルが正しいと思います。ここで何が問題なのか本当にわかりません。Sporkを再起動してみました。そして、最初の click_link テストをコメントアウトすると、2 番目のテストでエラーが表示されます。http://github.com/sambaek/sample_app のコードを参照してください

誰かが私を助けることができますか?本当にありがとう!

仕様/サポート/utilities.rb

include ApplicationHelper

仕様/リクエスト/static_pages_spec.rb

require 'spec_helper'

describe "Static pages" do

  subject { page }

  shared_examples_for "all static pages" do
    it { should have_selector('h1',    text: heading) }
    it { should have_selector('title', text: full_title(page_title)) }
  end

  describe "Home page" do
    before { visit root_path }

    let(:heading)    { 'Sample App' }
    let(:page_title) { '' }

    it_should_behave_like "all static pages"
    it { should_not have_selector 'title', text: '| Home' }
  end

  describe "Help page" do
    before { visit help_path }

    let(:heading)    { 'Help' }
    let(:page_title) { 'Help' }

    it_should_behave_like "all static pages"  
  end

  describe "About page" do
    before { visit about_path }

    let(:heading)    { 'About Us' }
    let(:page_title) { 'About Us' }

    it_should_behave_like "all static pages"
  end

  describe "Contact page" do
    before { visit contact_path }

    let(:heading)    { 'Contact' }
    let(:page_title) { 'Contact' }

    it_should_behave_like "all static pages"
  end

  it "should have the right links on the layout" do
    visit root_path
    click_link "About"
    page.should have_selector 'title', text: full_title('About Us')
    click_link "Help"
    page.should have_selector 'title', text: full_title('Help')
    click_link "Contact"
    page.should have_selector 'title', text: full_title('Contact')
    click_link "Home"
    click_link "Sign up now!"
    page.should have_selector 'title', text: full_title('Sign Up')
    click_link "sample app"
    page.should_not have_selector 'title', text: full_title(' | Home')
  end
end

仕様/ヘルパー/application_helper_spec.rb

require 'spec_helper'

describe ApplicationHelper do

  describe "full_title" do
    it "should include the page title" do
      full_title("foo").should =~ /foo/
    end

    it "should include the base title" do
      full_title("foo").should =~ /^Ruby on Rails Tutorial Sample App/
    end

    it "should not include a bar for the home page" do
      full_title("").should_not =~ /\|/
    end
  end
end

アプリ/ヘルパー/application_helper.rb

module ApplicationHelper
    def full_title(page_title)
        base_title = "Ruby on Rails Tutorial Sample App"
        if page_title.empty?
            base_title
        else
            "#{base_title} | #{page_title}"
        end
    end
end

ターミナル出力

rspec spec/

..F............

Failures:

  1) Static pages should have the right links on the layout
     Failure/Error: page.should have_selector 'title', text: full_title('About Us')
       expected css "title" with text "Ruby on Rails Tutorial Sample App | About Us" to return something
     # ./spec/requests/static_pages_spec.rb:52:in `block (2 levels) in <top (required)>'

Finished in 4.37 seconds
15 examples, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:49 # Static pages should have the right links on the layout
4

2 に答える 2

0

問題は、リンクが入ってどこにlayouts/footerlayouts/header行かないためです。仕様ではクリック可能です#が、適切なページではなく、移動するだけです。これらのリンクを修正すると、仕様が機能します。

app/views/layouts/_footer.html.erb

<li><%= link_to "About",   '/about' %></li>
<li><%= link_to "Contact", '/contact' %></li>

app/views/layouts/_header.html.erb

 <li><%= link_to "Home",    '/' %></li>
 <li><%= link_to "Help",    '/help' %></li>
于 2012-09-03T05:55:58.887 に答える
0

名前付きルート パス変数 (例: about_path) を使用し続けないのはなぜですか?

于 2013-12-23T09:27:40.663 に答える