2013-06-19 42 views
0

我花了几个小时阅读本书和github页面的代码,我似乎无法找到我的答案。我在第7.1.3章中试图通过以下测试。当我查看这些页面时,就我所知,一切正常。Rails教程3章7.1.3 rspec失败测试

user_pages_spec.rb

require 'spec_helper' 

describe "User pages" do 

    subject { page } 

    describe "signup page" do 
    before { visit signup_path } 

    it { should have_selector('h1',  text: 'Sign Up') }    (10) 
    it { should have_selector('title', text: full_title('Sign Up')) } (11) 
    end 

    describe "profile page" do 
    let(:user) { FactoryGirl.create(:user) } 
    before { visit user_path(user) } 

    it { should have_selector('h1',  text: 'user.name') }    (18) 
    it { should have_selector('title', text: 'user.name') }    (19) 
    end 
end 

我经历过的一切,我能想到的检查有什么可能出问题的文件。

应用/视图/用户/ new.html.erb

<% provide(:title, 'Sign Up') %> 
<h1>Sign Up</h1> 
<p>Find me in app/views/users/new.html.erb</p> 

**应用/视图/用户/ show.html.erb

<% provide(:title, @user.name) %> 
<h1><%= @user.name %></h1> 

应用程序/控制器/ users_controller .RB

class UsersController < ApplicationController 

    def show 
    @user = User.find(params[:id]) 
    end 

    def new 
    end 

end 

的config/routes.rb中

SampleApp::Application.routes.draw do 

    resources :users 

    match '/contact', :to => 'pages#contact' 
    match '/about', :to => 'pages#about' 
    match '/help', :to => 'pages#help' 

    match '/signup', :to => 'users#new' 

    root :to => 'pages#home' 

我想我已经连接所有相关的代码,请让我知道,如果添加任何东西都不会有所帮助。以下是我得到的实际错误。如果你能指出我在作品中抛出扳手的地方,我会非常感激。

rspec ./spec/requests/user_pages_spec.rb:10 # User pages signup page 
rspec ./spec/requests/user_pages_spec.rb:11 # User pages signup page 
rspec ./spec/requests/user_pages_spec.rb:18 # User pages profile page 
rspec ./spec/requests/user_pages_spec.rb:19 # User pages profile page 

感谢您的帮助和时间!

回答

0

删除第18和19行中的引号。这应该通过您的测试。

像这样:

describe "profile page" do 
    let(:user) { FactoryGirl.create(:user) } 
    before { visit user_path(user) } 

    it { should have_selector('h1', text: user.name) } 
    it { should have_selector('title', text: user.name) } 
    end 

也期待您的routes.rb。在rails教程中它很好

match '/help', to: 'static_pages#help' 
match '/about', to: 'static_pages#about' 
match '/contact', to: 'static_pages#contact' 

除非您已经使用名称页创建了静态页面视图。然后忘记我的routes.rb

+0

感谢您的回应,但没有奏效。还有什么我可以忽略的? – lostrennie

相关问题