2014-07-21 171 views
0

我目前正在Michael Hartl做Ruby on Rails教程,現在我在第3章。H最後,在使用佈局,提供和屈服之後,測試應該是成功的,但是,我我每次都得到3次失敗。Rails教程Ch。 3 Rspec失敗

我把這個測試它:

bundle exec rspec spec/requests/static_pages_spec.rb 

我得到這個回:

'Failures: 

1) StaticPages 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:33:in `block (3 levels) in <top (required)>' 

2) StaticPages 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:22:in `block (3 levels) in <top (required)>' 

3) StaticPages 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:11:in `block (3 levels) in <top (required)>' 

Finished in 0.24723 seconds 
6 examples, 3 failures 

Failed examples: 

rspec ./spec/requests/static_pages_spec.rb:31 # StaticPages About page should have the title 'About Us' 
rspec ./spec/requests/static_pages_spec.rb:20 # StaticPages Help page should have the title 'Help' 
rspec ./spec/requests/static_pages_spec.rb:9 # StaticPages Home page should have the title 'Home' 

Randomized with seed 17890' 

我根本無法找出問題。

這裏是我的佈局:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Ruby on Rails 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> 

這裏是我的家:

<% 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> 

而且我的Gemfile,如果需要的話:

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

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.0.8' 

# Use sqlite3 as the database for Active Record 
group :development 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 

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

# Use SCSS for stylesheets 
gem 'sass-rails', '4.0.1' 

# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '2.1.1' 

# Use CoffeeScript for .js.coffee assets and views 
gem 'coffee-rails', '4.0.1' 

# See https://github.com/sstephenson/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# Use jquery as the JavaScript library 
gem 'jquery-rails', '3.0.4' 

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks', '1.1.1' 

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '1.0.2' 

group :doc do 
    # bundle exec rake doc:rails generates the API under doc/api. 
    gem 'sdoc', '0.3.20', require: false 
end 

# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

# Use unicorn as the app server 
# gem 'unicorn' 

# Use Capistrano for deployment 
# gem 'capistrano', group: :development 

# Use debugger 
# gem 'debugger', group: [:development, :test] 

希望有人能幫助我,因爲我已用盡了所有的我的東西可能是錯誤的想法。也許我錯過了一些東西。感謝任何能夠回答的人。

回答

1

變化

<title>Ruby on Rails Sample App | <%= yield(:title) %></title> 

<title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title> 

,因爲這是你正在測試使用RSpec。

相關問題