uncaught throw :warden in Devise Testing

匿名 (未验证) 提交于 2019-12-03 02:07:01

问题:

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

回答1:

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



回答2:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!