LoginSignup
0
3

More than 5 years have passed since last update.

Rspecでユーザーのログインをテストするときにハマったこと

Posted at

uninitialized constant Devise::Test (NameError)

NoMethodError: undefined method `env' for nil:NilClass

コンソールで下記のようなエラーが吐かれた。

console
Failure/Error: @request.env["devise.mapping"] = Devise.mappings[:staff]
NoMethodError:
  undefined method `env' for nil:NilClass

ググってみると同じようなエラーに対して回答が寄せられていたので、そちらを参考に。
https://code.i-harness.com/ja/q/1a054b1

rails_helper.rb
RSpec.configure do |config|
  # 中略
  config.include Devise::Test::ControllerHelpers, type: :controller
end

deviseのバージョンが4.1.1以降だとヘルパーの記述が変更されるらしい。
https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3