ruby-on-rails - 未捕获的抛出 :warden in Devise Testing

标签 ruby-on-rails testing rspec devise warden

我刚刚开始测试 Devise。我无法理解为什么我会收到此错误::

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

这是我规范中的代码::

    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

有人解决了这个问题吗?我知道 github 上存在问题,但在他们的情况下,include Devise::TestHelpers 与我的情况不同。

我在这一行收到错误::subject.current_user.should_not be_nil

最佳答案

我看到这是一个非常古老的问题,但我遇到了类似的问题。这就是帮助我的原因。

如果你正在使用confirmable模块,不要忘记确认用户,否则抛出Warden异常。对您的代码进行适当的更改是:

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

更多信息可以在 Devise Wiki 中找到

关于ruby-on-rails - 未捕获的抛出 :warden in Devise Testing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9482739/

相关文章:

testing - TestCafe 'dynamic' 测试用例

ruby - 如何在共享上下文之间共享 RSpec let 变量?

ruby-on-rails - 如何使用 RSpec 测试 Pusher

ios - StoreKit验证错误 21002 : The data in the receipt-data property was malformed

ruby-on-rails - 自定义路由和声明授权

ruby-on-rails - 创建对象时不要使用引用的 id

ruby-on-rails - RVM 和 OSX Lion - 系统重启时 RVM 'forgets' gemsets

javascript - 进行浏览器测试时 Windows 版本重要吗?

ruby-on-rails - 工厂少女协会自引用父模型

ruby-on-rails - rails 上的 ruby 。用户模型的管理属性有多安全?