2013-06-21 76 views
1

我正在从Michael Hartl的教程学习Ruby on Rails。
现在我被困在9.2.1章。
下面是书中的代码:
Ruby on Rails(Michael Hart教程)授权错误(章节9.2.1)

authentication_pages_spec.erb 需要 'spec_helper'

describe "Authentication" do 

    subject { page } 

    describe "signin" do 
    before { visit signin_path } 

    describe "with invalid information" do 
     before { click_button "Sign in" } 

     it { should have_title('Sign in') } 
     it { should have_selector('div.alert.alert-error', text: 'Invalid') } 

     describe "after visiting another page" do 
     before { click_link "Home" } 
     it { should_not have_selector('div.alert.alert-error') } 
     end 
    end 
    end 

    describe "with valid information" do 
    let(:user) { FactoryGirl.create(:user) } 
    before { sign_in user } 

    it { should have_title(user.name) } 
    it { should have_link('Profile', href: user_path(user)) } 
    it { should have_link('Settings', href: edit_user_path(user)) } 
    it { should have_link('Sign out', href: signout_path) } 
    it { should_not have_link('Sign in', href: signin_path) } 

    describe "followed by signout" do 
     before { click_link "Sign out" } 
     it { should have_link('Sign in') } 
    end 
    end 
    describe "authorization" do 

    describe "for non-signed-in users" do 
     let(:user) { FactoryGirl.create(:user) } 

     describe "in the Users controller" do 

     describe "visiting the edit page" do 
      before { visit edit_user_path(user) } 
      it { should have_title('Sign in') } 
     end 

     describe "submitting to the update action" do 
      before { put user_path(user) } 
      specify { response.should redirect_to(signin_path) } 
     end 
     end 
    end 
    end 
end 

但是当我测试:

rspec spec/ 

有2级的错误,我不t知道如何解决在线:

it { should have_title('Sign in') } 

和线路:

specify { response.should redirect_to(signin_path) } 

以下是错误图像: http://i.stack.imgur.com/85WaX.png

+1

这些是什么错误? –

+0

哎呀,对不起! 这是图像。 http://i.stack.imgur.com/85WaX.png –

回答

0

你错过了before { sign_in user }describe "visiting the edit page" do块。

但你已经使用了正确的其它模块,如:

let(:user) { FactoryGirl.create(:user) } 
before { sign_in user } 
+0

这不起作用。还有其他解决方案吗? –

相关问题