当我完成了题为"填写布局"的第5章以及用户的初始创建后,我运行了rspec,得到了以下内容:
1) PagesController GET 'home' should have the right title
Failure/Error: response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Home")
expected following output to contain a <title>Ruby on Rails Tutorial Sample App | Home</title>
2) PagesController GET 'contact' should have the right title
Failure/Error: response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Contact")
expected following output to contain a <title>Ruby on Rails Tutorial Sample App | Contact</title>
3) PagesController GET 'about' should have the right title
Failure/Error: response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | About")
expected following output to contain a <title>Ruby on Rails Tutorial Sample App | About</title>
我已经做了大约一天了,我只是不知道我做错了什么?此外,页面启动也非常好
这是页面控制器代码需要"spec_helper"
describe PagesController do
render_views
describe "GET 'home'" do
it "should be successful" do
get 'home'
response.should be_success
end
it "should have the right title" do
get 'home'
response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Home")
end
end
describe "GET 'contact'" do
it "should be successful" do
get 'contact'
response.should be_success
end
it "should have the right title" do
get 'contact'
response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Contact")
end
end
describe "GET 'about'" do
it "should be successful" do
get 'about'
response.should be_success
end
it "should have the right title" do
get 'about'
response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | About")
end
end
end
这里还有我的应用程序/views/layouts/application.html.erb
<title><%= @title %></title>
这是我的布局_links_spec
require 'spec_helper'
it "should have a Home page at '/'" do
get '/'
response.should have_selector('title', :content => "Home")
end
it "should have a Contact page at '/contact'" do
get '/contact'
response.should have_selector('title', :content => "Contact")
end
it "should have have an About page at '/about" do
get '/about'
response.should have_selector('title', :content => "About")
end
it "should have a Help pageat '/help'" do
get '/help'
response.should have_selector('title', :content => "Help")
end
it "should have a signup page at '/signup'" do
get '/signup'
response.should have_selector('title', :content => "Sign up")
end
it "should have the right links on the layout" do
visit root_path
response.should have_selector('title', :content => "Home")
end
end
确保包含render_views
require 'spec_helper'
describe UsersController do
render_views
describe "GET 'new'" do
it "should be successful" do
get :new
response.should be_success
end
it "should have the right title" do
get :new
response.should have_selector("title", :content => "Sign up")
end
end
end
我花了一些时间才弄清楚确切的错误是什么,但请确保按照Mike教程中的说明进行操作。
迈克的工作效率很高,也很彻底,但如果你跳过一步就会出错。我看到了同样的问题,首先您需要确保使用的是列表5.20中更新最多的static_pages_spec.rb
,列表5.23的更新最多的路由文件,并确保删除了publicindex.html
文件。
一旦你完成了这些步骤,你的错误就会消失。