使用RSpec测试设计时出现Warden :: Proxy错误

时间:2019-06-21 20:30:47

标签: testing rspec devise

为自定义SessionsController运行简单的RSpec测试时,我收到有关Warden :: Proxy:的错误

 Devise could not find the `Warden::Proxy` instance on your request environment.

我尝试添加

  config.include Devise::Test::ControllerHelpers, type: :controller
  config.include Warden::Test::Helpers

到rails_helper.rb。

我还添加了

  include Devise::Controllers::Helpers
  include Devise::Test::ControllerHelpers

RSpec.describe SessionsController, type: :controller do
  include Devise::Controllers::Helpers
  include Devise::Test::ControllerHelpers

  it "should show login page" do
    get :new
    expect(response.status).to eq(200)
  end
end
  1) SessionsController should show login page
     Failure/Error: request.env['warden'] or raise MissingWarden

     Devise::MissingWarden:
       Devise could not find the `Warden::Proxy` instance on your request environment.
       Make sure that your application is loading Devise and Warden as expected and that the `Warden::Manager` middleware is present in your middleware stack.
       If you are seeing this on one of your tests, ensure that your tests are either executing the Rails middleware stack or that your tests are using the `Devise::Test::ControllerHelpers` module to inject the `request.env['warden']` object for you.

0 个答案:

没有答案