2014-03-13 127 views
-1

這裏是視圖:回報率RSpec的測試失敗

<!-- Only have to provide what is not provided in the layout. 
    The layour is the skeleton. --!> 
<div class="center hero-unit"> 
    <h1>Sample App</h1> 

    <h2> 
    This is the home page for 
    <%= link_to "Ruby on Rails Tutorial", 'http://railstutorial.org/' %> 
    sample application! 
    </h2> 

    <%= link_to "Sign up now!", signup_path, class: "btn btn-large btn-primary" %> 
</div> 

<%= link_to image_tag("rails.png", alt: "Rails"), 'http://railstutorial.org/' %> 

我有一個類似的問題,在此之前曾與來訪的測試連接錯誤的事情。我在主頁上使用了檢查,以確保標題真的在那裏,即使我的測試失敗了。

下面是測試:

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_title(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_title('| Home') } 
    end 
end 

以下是錯誤:

Failures: 

    1) Static pages Home page it should behave like all static pages 
    Failure/Error: it { should have_selector('h1', text: heading) } 
     expected #has_selector?("h1", {:text=>"Sample App"}) to return true, got false 
    Shared Example Group: "all static pages" called from ./spec/requests/static_pages_spec.rb:17 
    # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>' 

Finished in 0.44614 seconds 
30 examples, 1 failure 

Failed examples: 

rspec ./spec/requests/static_pages_spec.rb:8 # Static pages Home page it should behave like all static pages 

回答

1

的問題是在這裏

<!-- Only have to provide what is not provided in the layout. 
    The layour is the skeleton. --!> 

這不是一個正確的HTML註釋語法。結束評論標記應爲-->而不是--!>。使用以下內容。

<!-- Only have to provide what is not provided in the layout. 
    The layour is the skeleton. --> 

您的測試失敗,因爲您的HTML註釋未終止,因此您的H1缺失。