Michael Hartl guide chapter 5 rspec issue
Once I completed Chapter 5 which titled "filling in the lay out" and also the initial creation of the users, I ran rspec and I get the following:
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>
I have been working on this for a about a day now and I just do not know what I am doing wrong? Also the pages launch perfectly fine as well
here is the pagescontroller code require '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
also here is my app/views/layouts/application.html.erb
<title><%= @title %></title>
here is my layout_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
Make sure you've included 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
It took me some time to figure out what the exact error was, but make sure you're following the instructions as they're laid out in the Mike's tutorial.
Mike's very efficient and thorough, but if you skip a step you'll get errors. I saw the same issue and first you need to make sure you're using the most updated static_pages_spec.rb
from listing 5.20, the most updated routes file from listing 5.23 and make sure that you delete the public\index.html
file.
Your errors should go away once you've completed those steps.
精彩评论