我目前正在做Michael Hartl的Ruby on Rails教程,现在我正在进行第3章。最后,在使用布局,提供和屈服之后,测试应该是成功的,但是,我得到了每次3次失败。
我把它放进去测试它:
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]
希望有人可以帮助我,因为我已经用尽了所有可能出错的想法。也许我错过了一些东西。感谢能够回答的任何人。
答案 0 :(得分:1)
更改
<title>Ruby on Rails Sample App | <%= yield(:title) %></title>
到
<title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>
因为这是您使用rspec测试的内容。