Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uncaught throw :warden in Devise Testing

I have just begun with testing Devise. I am unable to understand of why i am getting this error ::

Failure/Error: subject.current_user.should_not be_nil
 ArgumentError:
   uncaught throw :warden

This is the code in my spec ::

    require "spec_helper"

    describe Devise::PasswordsController do
      include Devise::TestHelpers
        before(:each) do
            user = Factory(:user)
            @request.env["devise.mapping"] = Devise.mappings[:user]
            sign_in user
        end
        it "should have a current user" do
                subject.current_user.should_not be_nil
        end
    end

Has anyone gotten a fix around this issue ? I know there are issues on github but in their case include Devise::TestHelpers was not present unlike in my case.

I am getting an error on this line :: subject.current_user.should_not be_nil

like image 597
Kaushik Thirthappa Avatar asked Feb 28 '12 13:02

Kaushik Thirthappa


2 Answers

I see this is a very old question, but I came across similar issue. This is what helped me.

If you're using confirmable module, don't forget to confirm user, otherwise the Warden exception is thrown. Appropriate change to your code would be:

before(:each) do
    user = Factory(:user)
    user.confirmed_at = Time.zone.now
    user.save
    @request.env["devise.mapping"] = Devise.mappings[:user]
    sign_in user
end

More info could be found in Devise Wiki

like image 197
rdamborsky Avatar answered Nov 10 '22 16:11

rdamborsky


uncaught throw :warden happens when authenticate_user! fails.

Figure out why your the user's authentication is a failing, and you'll have solved your problem.

like image 20
Pieter van der Merwe Avatar answered Nov 10 '22 16:11

Pieter van der Merwe