2014-01-16 6 views
1

그래서 레일 튜토리얼을 따르려고 노력했지만 제목을 약간 동적으로 만들었습니다. 내가 this part에 도착하고레일 튜토리얼 3 장 Rspec 테스트가 실패했습니다

$ bundle exec rspec spec/requests/static_pages_spec.rb 

을 실행하면 나는 다음과 같은 오류를받을

Failures: 

    1) Static pages Help page should have the title 'Help' 
    Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help") 
     expected #has_title?("Ruby on Rails Tutorial Sample App | Help") to return true, got false 
    # ./spec/requests/static_pages_spec.rb:27:in `block (3 levels) in <top (required)>' 

    2) Static pages Home page should have the title 'Home' 
    Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | Home") 
     expected #has_title?("Ruby on Rails Tutorial Sample App | Home") to return true, got false 
    # ./spec/requests/static_pages_spec.rb:14:in `block (3 levels) in <top (required)>' 

    3) Static pages About page should have the title 'About Us' 
    Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us") 
     expected #has_title?("Ruby on Rails Tutorial Sample App | About Us") to return true, got false 
    # ./spec/requests/static_pages_spec.rb:40:in `block (3 levels) in <top (required)>' 

Finished in 0.1826 seconds 
6 examples, 3 failures 

Failed examples: 

rspec ./spec/requests/static_pages_spec.rb:25 # Static pages Help page should have the title 'Help' 
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the title 'Home' 
rspec ./spec/requests/static_pages_spec.rb:38 # Static pages About page should have the title 'About Us' 

이 내 집, 도움말 및 정보 뷰처럼 것입니다.

<% provide(:title, 'Home') %> 
<h1>Sample App</h1> 
<p> 
    This is the home page for the 
    <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> 
    sample application. 
</p> 

도움말

<% provide(:title, 'Help') %> 
<h1>Help</h1> 
<p> 
    Get help on the Ruby on Rails Tutorial at the 
    <a href="http://railstutorial.org/help">Rails Tutorial help page</a>. 
    To get help on this sample app, see the 
    <a href="http://railstutorial.org/book">Rails Tutorial book</a>. 
</p> 

소개

<%= provide(:title, 'About Us') %> 
<h1>About Us</h1> 
<p> 
    The <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> 
    is a project to make a book and screencasts to teach web development 
    with <a href="http://rubyonrails.org/">Ruby on Rails</a>. This 
    is the sample application for the tutorial. 
</p> 

그리고 이것은 내 응용 프로그램보기

<!DOCTYPE html> 
<html> 
<head> 
    <title>Ruby on Rails Tutorial Sample App | <%= yield (:title) %></title> 
    <%= stylesheet_link_tag "application", media: "all", 
              "data-turbolinks-track" => true %> 
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %> 
    <%= csrf_meta_tags %> 
</head> 
<body> 

<%= yield %> 

</body> 
</html> 
,536,913,632입니다 10

그리고 내 정적 페이지 사양

require 'spec_helper' 

describe "Static pages" do 

    describe "Home page" do 

    it "should have the content 'Sample App'" do 
     visit '/static_pages/home' 
     expect(page).to have_content('Sample App') 
    end 

    it "should have the title 'Home'" do 
     visit '/static_pages/home' 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App | Home") 
    end 
    end 

    describe "Help page" do 

    it "should have the content 'Help'" do 
     visit '/static_pages/help' 
     expect(page).to have_content('Help') 
    end 

    it "should have the title 'Help'" do 
     visit '/static_pages/help' 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help") 
    end 
    end 

    describe "About page" do 

    it "should have the content 'About Us'" do 
     visit '/static_pages/about' 
     expect(page).to have_content('About Us') 
    end 

    it "should have the title 'About Us'" do 
     visit '/static_pages/about' 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us") 
    end 
    end 
end 

그리고 마지막으로 내 gemfile 아래 (= 전에 첫 번째 줄에 제공 통지) 같은

source 'https://rubygems.org' 
ruby '2.1.0' 
#ruby-gemset=railstutorial_rails_4_0 

gem 'rails', '4.0.2' 

group :development, :test do 
    gem 'sqlite3', '1.3.8' 
    gem 'rspec-rails', '2.13.1' 
end 

group :test do 
    gem 'selenium-webdriver', '2.35.1' 
    gem 'capybara', '2.1.0' 
end 

gem 'sass-rails', '4.0.1' 
gem 'uglifier', '2.1.1' 
gem 'coffee-rails', '4.0.1' 
gem 'jquery-rails', '3.0.4' 
gem 'turbolinks', '1.1.1' 
gem 'jbuilder', '1.0.2' 

group :doc do 
    gem 'sdoc', '0.3.20', require: false 
end 

group :production do 
    gem 'pg', '0.15.1' 
    gem 'rails_12factor', '0.0.2' 
end 

답변

1

변경보기를.

<%= provide(:title, 'Home') %> 
<h1>Sample App</h1> 
<p> 
    This is the home page for the 
    <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> 
    sample application. 
</p> 
0

은 수동으로 각 페이지에 가서 제목 자신을 확인하는 시도 가지고 집으로 세 가지보기

모두 동일합니까?

나는 당신이 프로젝트에 제공 한 모든 것을 그대로 붙여 넣었습니다. (제가 이전에 튜토리얼을 했으므로 이미 static_pages 컨트롤러로 설정을했습니다) 그리고 모든 테스트가 통과되었습니다. 내가보기에 파일 이름이나 라우트 파일의 이름이 섞여있을 수도 있지만 콘텐츠 테스트는 통과 할 수 없다고 말했을 것입니다. 나는 당신의 파일 중 하나가 에디터에 의해 잘못된 인코딩으로 저장되었거나 그 라인을 따라 다른 것으로 저장되었을 수도 있습니다. 또한 테스트를 실행하기 전에 실제로 모든 파일을 저장했는지 확인하십시오.

또한 <% provide ...의 경우 =이 필요하지 않으므로 대략보기에서 제거해야합니다.

0

나는 당신과 같이 당신의 routes.rb 파일에 '접촉'페이지를 추가 잊어 버린 것 같아요 :

SampleApp::Application.routes.draw do 
    get "static_pages/home" 
    get "static_pages/help" 
    get "static_pages/about" 
    get "static_pages/contact" 
0

이 시도 :

static_pages_spec.rb

require 'spec_helper' 

describe "Static pages" do 

    let(:base_title) { "Ruby on Rails Tutorial Sample App" } 

    describe "Home page" do 

    it "should have the content 'Sample App'" do 
     visit '/static_pages/home' 
     expect(page).to have_content('Sample App') 
    end 

    it "should have the title 'Home'" do 
     visit '/static_pages/home' 
     #expect(page).to have_title("#{base_title} | Home") 
     page.should have_title("#{base_title} | Home") 
    end 
    end 

    describe "Help page" do 

    it "should have the content 'Help'" do 
     visit '/static_pages/help' 
     expect(page).to have_content('Help') 
    end 

    it "should have the title 'Help'" do 
     visit '/static_pages/help' 
     #expect(page).to have_title("#{base_title} | Help") 
     page.should have_title("#{base_title} | Help") 
    end 
    end 

    describe "About page" do 

    it "should have the content 'About Us'" do 
     visit '/static_pages/about' 
     expect(page).to have_content('About Us') 
    end 

    it "should have the title 'About Us'" do 
     visit '/static_pages/about' 
     page.should have_title("#{base_title} | About Us") 
    end 
    end 

    describe "Contact page" do 

    it "should have the content 'Contact'" do 
     visit '/static_pages/contact' 
     expect(page).to have_content('Contact') 
    end 

    it "should have the title 'Contact'" do 
     visit '/static_pages/contact' 
    # expect(page).to have_title("#{base_title} | Contact") 
     page.should have_title("#{base_title} | Contact") 
    end 
    end 
end 

응용 프로그램 .html.erb

<!DOCTYPE html> 
    <html> 
    <head> 
    <title>Ruby on Rails Tutorial Sample App | <%= yield(:title)%></title> 
    <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> 
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %> 
    <%= csrf_meta_tags %> 
    </head> 
    <body> 
<%= yield %> 

</body> 
</html> 

보석류 '카피 바라', '2.1.0 '

제목의 공백이 적당 함

관련 문제