読者です 読者をやめる 読者になる 読者になる

【Rails4】Devise::MissingWarden エラーへの対処

RepecでControllerのテストを実行した際に発生。
以下エラー文

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.


原因
Device gem によるプロキシエラー。

対応

f you're using RSpec, you can put the following inside a file named spec/support/devise.rb or in your spec/spec_helper.rb (or spec/rails_helper.rb if you are using rspec-rails):

RSpec.configure do |config|
  config.include Devise::Test::ControllerHelpers, type: :controller
  config.include Devise::Test::ControllerHelpers, type: :view
end

とのことなので以下の様に設定を追加

spec/rails_helper.rb

RSpec.configure do |config|
  config.include Devise::Test::ControllerHelpers, type: :controller
  config.include Devise::Test::ControllerHelpers, type: :view
end