2012-05-18 4 views
3

rspec에서이 오류가 발생합니다. 그러나 코드가 전달되어야합니다. Rspec이 불평하는 모든 선별자가 존재합니다. 여기 전달해야 할 때이 사양이 실패하는 이유는 무엇입니까?

FF.FFFFFF 

Failures: 

    1) StaticPages Home page should have the h1 'Sample App' 
    Failure/Error: page.should have_selector('h1', text: 'Sample App') 
     expected css "h1" with text "Sample App" to return something 
    # ./spec/requests/static_pages_spec.rb:9:in `block (3 levels) in <top (required)>' 

    2) StaticPages Home page should have the base title 
    Failure/Error: page.should have_selector('title', text: "Ruby on Rails Tutorial Sample App") 
     expected css "title" with text "Ruby on Rails Tutorial Sample App" to return something 
    # ./spec/requests/static_pages_spec.rb:14:in `block (3 levels) in <top (required)>' 

    3) StaticPages Help page should have the h1 'Help' 
    Failure/Error: page.should have_selector('h1',text: "Help") 
     expected css "h1" with text "Help" to return something 
    # ./spec/requests/static_pages_spec.rb:28:in `block (3 levels) in <top (required)>' 

    4) StaticPages Help page should have the title 'Help' 
    Failure/Error: page.should have_selector('title', text: "Ruby on Rails Tutorial Sample App | Help") 
     expected css "title" with text "Ruby on Rails Tutorial Sample App | Help" to return something 
    # ./spec/requests/static_pages_spec.rb:33:in `block (3 levels) in <top (required)>' 

    5) StaticPages About page should have the h1 'About us' 
    Failure/Error: page.should have_selector('h1', text: 'About Us') 
     expected css "h1" with text "About Us" to return something 
    # ./spec/requests/static_pages_spec.rb:41:in `block (3 levels) in <top (required)>' 

    6) StaticPages About page should have the title 'About Us' 
    Failure/Error: page.should have_selector('title', text: "Ruby on Rails Tutorial Sample App | About Us") 
     expected css "title" with text "Ruby on Rails Tutorial Sample App | About Us" to return something 
    # ./spec/requests/static_pages_spec.rb:46:in `block (3 levels) in <top (required)>' 

    7) StaticPages Contact pages should have the h1 'Contact' 
    Failure/Error: page.should have_selector('h1', text: 'Contact') 
     expected css "h1" with text "Contact" to return something 
    # ./spec/requests/static_pages_spec.rb:53:in `block (3 levels) in <top (required)>' 

    8) StaticPages Contact pages Should have the title page 'Contact' 
    Failure/Error: page.should have_selector('title', 
     expected css "title" with text "Ruby on Rails Tutorial Sample App | Contact" to return something 
    # ./spec/requests/static_pages_spec.rb:59:in `block (3 levels) in <top (required)>' 

Finished in 0.31051 seconds 
9 examples, 8 failures 

Failed examples: 

rspec ./spec/requests/static_pages_spec.rb:7 # StaticPages Home page should have the h1 'Sample App' 
rspec ./spec/requests/static_pages_spec.rb:12 # StaticPages Home page should have the base title 
rspec ./spec/requests/static_pages_spec.rb:26 # StaticPages Help page should have the h1 'Help' 
rspec ./spec/requests/static_pages_spec.rb:31 # StaticPages Help page should have the title 'Help' 
rspec ./spec/requests/static_pages_spec.rb:39 # StaticPages About page should have the h1 'About us' 
rspec ./spec/requests/static_pages_spec.rb:44 # StaticPages About page should have the title 'About Us' 
rspec ./spec/requests/static_pages_spec.rb:51 # StaticPages Contact pages should have the h1 'Contact' 
rspec ./spec/requests/static_pages_spec.rb:56 # StaticPages Contact pages Should have the title page 'Contact' 

는 사양이다

require 'spec_helper' 

describe "StaticPages" do 

    describe "Home page" do 

    it "should have the h1 'Sample App'" do 
    get '/static_pages/home' 
     page.should have_selector('h1', text: 'Sample App') 
    end 

    it "should have the base title" do 
     get '/static_pages/home' 
     page.should have_selector('title', text: "Ruby on Rails Tutorial Sample App") 
    end 

    it "should not havea custom page title " do 
     get '/static_pages/home' 
     page.should_not have_selector('title', text: '| Home') 
    end 
    end 
    #end home page spec 

    describe "Help page" do 

    it "should have the h1 'Help'" do 
     get '/static_pages/help' 
     page.should have_selector('h1',text: "Help") 
    end 

    it "should have the title 'Help'" do 
     get 'static_pages/help' 
     page.should have_selector('title', text: "Ruby on Rails Tutorial Sample App | Help") 
    end 
    end 

    describe "About page" do 

    it "should have the h1 'About us' " do 
     get '/static_pages/about' 
     page.should have_selector('h1', text: 'About Us') 
    end 

    it "should have the title 'About Us'" do 
     get '/static_pages/about' 
     page.should have_selector('title', text: "Ruby on Rails Tutorial Sample App | About Us") 
    end 
    end 

    describe "Contact pages" do 
    it "should have the h1 'Contact'" do 
     get '/static_pages/contact' 
     page.should have_selector('h1', text: 'Contact') 
    end 

    it "Should have the title page 'Contact'" do 
     get '/static_pages/contact' 
     #this test is passing but the code in the book is not the same as what is below 
     page.should have_selector('title', 
            text: "Ruby on Rails Tutorial Sample App | Contact") 
    end 
    end 
end 

home.html.erb보기

<div> 
    <h1>Welcome to the Sample App</h1> 
    <h2>This is the home page for the 
     <a href="http://railstutorial.org">Ruby on Rails Tutorial</a> 
     sample application 
    <h2> 
     <%= link_to "Sign up now!", '#', class: "btn btn-large btn-primary"%> 
</div> 

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

contact.html.erb

<% provide(:title, 'Contact') %> 
<h1>Contact</h1> 
<p> 
    Contact Ruby on rails tutorial about he sample app at the 
    <a href="http://railstutorial.org/contact">contact page</a> 
</p> 

about.html 기본. 예 :

01 테스트 시도를 사용 visit 방법 대신 23,516,
<% provide(:title,'About Us') %> 
    <h1>About Us</h1> 
    <p> 
    <a href="http://railstutorial.orb">Ruby on Rails Tutorial</a> 
    is a project to make a book and screencasts to teach web development 
    <a href="http://rubyonrails.org">Ruby on Rails</a> This 
    is the sampel app for the tutorial 
    </p> 
+0

당신이 셨나요 아웃입니까? 타이틀과 관련해서도 동일한 튜토리얼에서 동일한 문제가 발생할 수 있습니다. – mfaerevaag

답변

관련 문제