vendredi 21 juin 2019

Warden::Proxy error when testing devise with RSpec

When running a simple RSpec test for a custom SessionsController I'm receiving an error regarding Warden::Proxy:

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

I've tried adding

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

to the rails_helper.rb.

I've also added

  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.

Aucun commentaire:

Enregistrer un commentaire