2013-05-28 100 views
0

我正在慢慢努力通過Michael Hartl出色的Ruby on Rails教程。 一切都很順利..直到第五章的練習。現在我很困難。 在實際練習部分中進行了詳細的更改後,我的RSpec測試現在失敗了。Rspec測試現在失敗 - 陷入第5章 - Hartl的Ruby on Rails教程

  • 請注意,我正在運行SPORK(但當我不使用SPORK時,測試也失敗)。

下面是輸出,我從每個測試的靜態頁面得到的一個例子:

Static pages Home page it should behave like all static pages Failure/Error: it { should have_selector('title', text: full_title(page_title)) } TypeError: can't convert RSpec::Matchers::BuiltIn::Include to String Shared Example Group: "all static pages" called from ./spec/requests/static_pages_spec.rb:19 # (eval):2:in has_selector?' # ./spec/requests/static_pages_spec.rb:9:in block (3 levels) in '

這裏是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 } 

    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 root_path } 
    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: '| Help' } 
end 

describe "About 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: '| About' } 
end 

describe "Contact 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: '| Contact' } 

end 
+0

這可能是有益的,看看static_pages_spec.rb。你可以發佈嗎? –

+0

你的full_title函數是否返回一個String? 在rails控制檯中,試試這個: helper.full_title(「test」)。class –

+0

Hi Sam,posted static_pages_spec.rb –

回答

1

謝謝那些誰好心試圖幫助我。

最後我解決了它 - 發現我不小心在留下了一些冗餘的代碼utilities.rb

只有線應該是在按章5月底該文件是:

include ApplicationHelper 

巴扎

相關問題