“undefined method `env' for nil:NilClass” in 'setup_controller_for_warden' error when testing Devise using Rspec

后端 未结 10 2016
陌清茗
陌清茗 2020-12-09 14:31

I\'m trying to create a spec for a sign out flow by using factorygirl to create a user and then use Devise\'s sign_in method to authenticate the user, then use

10条回答
  •  情歌与酒
    2020-12-09 15:10

    For the sake of being complete, with Rails 5 and RSpec I have run into similar issues when using the latest helpers, as they need to be set explicitly with the type when not used as a superclass.

    So if you find yourself receiving there errors in your model tests there's a pretty good chance the type is not set.

    Here's what I use in the spec_helper:

      config.include Devise::Test::ControllerHelpers, type: :controller
      config.include Devise::Test::ControllerHelpers, type: :view
      config.include Devise::Test::IntegrationHelpers, type: :feature
    

    I know that the docs do mention this, but there are times when you may run across an older blog that gives you an older approach, or upgrading from an older setup, and next thing you know this happens.

提交回复
热议问题