2013-06-19 50 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

相關問題