运行以下命令时:
捆绑exec rspec spec / requests / static_pages_spec.rb
我收到以下错误
FF.......
Failures:
1) Static pages 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:6:in `block (3 levels) in <top (required)>'
2) Static pages Home page should have the base title
Failure/Error: page.should have_selector('title',
expected css "title" with text "Ruby on Rails Tutorial Sample App" to return something
# ./spec/requests/static_pages_spec.rb:10:in `block (3 levels) in <top (required)>'
Finished in 0.38131 seconds
9 examples, 2 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:4 # Static pages Home page should have the h1 'Sample App'
rspec ./spec/requests/static_pages_spec.rb:8 # Static pages Home page should have the base title
我的static_pages_spec.rb看起来像这样:
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the h1 'Sample App'" do
visit root_path
page.should have_selector('h1', text: 'Sample App')
end
it "should have the base title" do
visit root_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit root_path
page.should_not have_selector('title', text: '| Home')
end
end
describe "Help page" do
it "should have the h1 'Help me'" do
visit help_path
page.should have_selector('h1', text: 'Help me')
end
it "should have the title 'Help me'" do
visit help_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App | Help me")
end
end
describe "About page" do
it "should have the h1 'About us'" do
visit about_path
page.should have_selector('h1', text: 'About us')
end
it "should have the title 'About us'" do
visit about_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App | About us")
end
end
describe "Contact page" do
it "should have the h1 'Contact'" do
visit contact_path
page.should have_selector('h1', text: 'Contact')
end
it "should have the title 'Contact'" do
visit contact_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App | Contact")
end
end
end
my routes.rb
SampleApp::Application.routes.draw do
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
end
我之前有过9/9的失败,但之后我又添加了
config.include Rails.application.routes.url_helpers
到spec / rspec_helper.rb,现在我已经离开上面的失败了
答案 0 :(得分:0)
您需要删除public / index.html文件。删除后,您的代码运行正常。
检查发生了什么的方法:
gem "launchy"
添加到您的Gemfile save_and_open_page
醇>