uncaught throw :warden in Devise Testing
Asked Answered
S

2

24

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

Scissile answered 28/2, 2012 at 13:24 Comment(2)
Did you find a fix for this problem?Pomcroy
@Zabba, ya, i just knocked off the user loading from the Factory and mainly, I did two things. 1) Make Sure that this is not an integration test and 2) call the function from the ControllerMacros login_userScissile
O
72

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

Offenbach answered 9/7, 2013 at 6:58 Comment(6)
BTW you can just do user.confirm! as shorthand for confirmed_at and saving.Evaevacuant
Great find, this answer needs to be accepted @ktkaushikRife
I had some problem with the fixture: this one works gist.github.com/henrydjacob/1344451Belfast
@Rife Done ! close to 2 years late, but better late than never. Sorry. :)Scissile
If you use fixtures you can just add confirmed_at: 2017-08-01 to your fixture for the model you are trying to login_as.Chekhov
Add this to your factory. confirmed_at { Time.zone.now }Cordiality
S
4

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.

Surat answered 23/2, 2016 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.