2013-08-07 2 views
0

필자는 좀 더 정교한 테스트를 마칠 예정이지만, 자동 생성 된 rspec 테스트로 시작할 수는 없습니다. 아래는 오류 코드 다음의 코드입니다. 내가 추가 한 puts 호출은 상황이 예상대로 작동 함을 의미합니다. 로그인 한 사용자를 표시 할 수없는 이유는 무엇입니까? 감사합니다컨트롤러 testrspec with devise users_controller_spec

describe UsersController do 



before (:each) do 
    @user = FactoryGirl.create(:user) 
    s = sign_in @user 
    puts "signed in " + s.to_s 
    end 

    describe "GET 'show'" do 

    it "should be successful" do 
     puts "u #{@user.name}" 
     get :show, :id => @user.id 
     response.should be_success 
    end 

    it "should find the right user" do 
     get :show, :id => @user.id 
     assigns(:user).should == @user 
    end 

    end 

실패 :

1) UsersController GET 'show' should find the right user 
    Failure/Error: assigns(:user).should == @user 
     expected: #<User id: 13, email: "[email protected]", encrypted_password: "$2a$04$oPxM0081ApmasEvX.wJ1dODL7.VsotWj06blfE8ve3B1...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2013-08-07 15:02:55", updated_at: "2013-08-07 15:02:55", name: "Test User", role: nil> 
      got: nil (using ==) 
    # ./spec/controllers/users_controller_spec.rb:21:in `block (3 levels) in <top (required)>' 

    2) UsersController GET 'show' should be successful 
    Failure/Error: response.should be_success 
     expected success? to return true, got false 
    # ./spec/controllers/users_controller_spec.rb:16:in `block (3 levels) in <top (required)>' 

Finished in 0.09869 seconds 
2 examples, 2 failures 

여기 내 users_controller입니다 : 각 :

class UsersController < ApplicationController 
    before_filter :authenticate_user! 

    def index 
    authorize! :index, @user, :message => 'Not authorized as an administrator.' 
    @users = User.all 
    end 

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

    def update 
    authorize! :update, @user, :message => 'Not authorized as an administrator.' 
    @user = User.find(params[:id]) 
    if @user.update_attributes(params[:user], :as => :admin) 
     redirect_to users_path, :notice => "User updated." 
    else 
     redirect_to users_path, :alert => "Unable to update user." 
    end 
    end 

    def destroy 
    authorize! :destroy, @user, :message => 'Not authorized as an administrator.' 
    user = User.find(params[:id]) 
    unless user == current_user 
     user.destroy 
     redirect_to users_path, :notice => "User deleted." 
    else 
     redirect_to users_path, :notice => "Can't delete yourself." 
    end 
    end 
end 
+1

'UsersController'를 (를) 공유 할 수 있습니까? –

답변

0

사용자가 대신 전에서의 각 it "should ..." do 블록의 시작에서 로그인 가진 시도가. 나는 비슷한 문제가 있다는 것을 기억하고, 올바르게 기억한다면, 그것을 고쳐야한다고 생각한다. 또한, 당신이 가지고 있다고 가정합니다 sign_in 작동하고 있기 때문에, 당신은 devise test_helpers를 포함되어 있지만 그렇지 않은 경우에도 문제의 일부가 될 수 있습니다. 희망이 도움이됩니다!

관련 문제