2011-06-02 65 views
0

一旦我完成了第5章,其标题为“在填补布局”,也是用户的初始创建,我跑rspec的,我得到如下:迈克尔·哈特尔指南第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> 

我一直在这工作了大约一天,我只是不知道我做错了什么?另外,网页推出完美的罚款以及

这里是pagescontroller代码 需要 '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 

也在这里是我的应用程序/视图/布局/ application.html.erb

<title><%= @title %></title> 

这是我的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 
+0

请向我们展示第5章中导致此问题的相关代码或特定部分。 – 2011-06-02 23:02:35

+0

我的代码被添加 – matt 2011-06-02 23:37:40

回答

3

确保你已经i ncluded 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 
+0

确保你已经包含了render_views!就是这个!。 – mdskinner 2012-03-05 00:35:43

1

我花了一些时间来找出确切的错误是,但要确保你按照指示,因为它们可以在Mike的教程布局。

迈克的非常高效和彻底,但如果你跳过一步你会得到错误。我看到了同样的问题,首先您需要确保使用列表中最新的static_pages_spec.rb 5.20,列表中最新的路由文件5.23并确保您删除public\index.html文件。

完成这些步骤后,您的错误应该消失。

相关问题