2013-09-28 28 views
1

閱讀第5章5.3.4節(漂亮規範)中的Harlts教程。 即使按照所有說明我收到此錯誤。靜態頁面主頁失敗/錯誤:it {should have_title(full_title('home'))

Static pages Contact page 
    Failure/Error: it { should have_title(full_title('Contact')) } 
     expected #has_title?("Ruby on Rails Tutorial Sample App | Contact") to return true, got false 
    # ./spec/requests/static_pages_spec.rb:39:in `block (3 levels) in <top (required)>' 

Finished in 0.29544 seconds 
11 examples, 3 failures 

Failed examples: 

rspec ./spec/requests/static_pages_spec.rb:25 # Static pages Help page 
rspec ./spec/requests/static_pages_spec.rb:32 # Static pages About page 
rspec ./spec/requests/static_pages_spec.rb:39 # Static pages Contact page 

這裏是規格/支持/ utilities.rb文件

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 

的內容和static_pages_spec.rb文件

require 'spec_helper' 

describe "Static pages" do 

    subject { page } 

    describe "Home page" do 
    before { visit root_path } 

    it { should have_content('Sample App') } 
    it { should have_title(full_title('home')) } 
    it { should_not have_title('| Home') } 
    end 

    describe "Help page" do 
    before { visit help_path } 

    it { should have_content('Help') } 
    it { should have_title(full_title('Help')) } 
    end 

    describe "About page" do 
    before { visit about_path } 

    it { should have_content('About') } 
    it { should have_title(full_title('About')) } 
    end 

    describe "Contact page" do 
    before { visit contact_path } 

    it { should have_content('Contact') } 
    it { should have_title(full_title('Contact')) } 
    end 
end 

回答

0

主頁標題的內容文本僅用於顯示Ruby on Rails Tutorial Sample App而不包含| Home部分。

因此改變

describe "Home page" do 
    before { visit root_path } 

    it { should have_content('Sample App') } 
    it { should have_title(full_title('home')) } 
    it { should_not have_title('| Home') } 
end 

describe "Home page" do 
    before { visit root_path } 

    it { should have_content('Sample App') } 
    it { should have_title(full_title('')) } 
    it { should_not have_title('| Home') } 
end 

那麼5日線取出home

+0

「家」並不是唯一一個導致問題與有關,接觸發生,幫助部分太.. – Abhinay

+0

和其他部分喜歡什麼,接觸相同的問題也發生了那些人也。 – Abhinay