3
votes

In a Rails 3.28 application using Devise, I setup a controller that checks whether a user is logged in or not with if user_signed_in?. Once the tests hit this line, I always get a undefined method 'authenticate!' for nil:NilClass error. I wanted to test some code in a scenario that no user is logged in.

I am thinking that I need to setup the tests according to the options specified in the Devise Wiki here, however, all the instructions pertain to rspec.

In particular, I think I need to have the following to work in minitest:

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
  config.extend ControllerMacros, :type => :controller
end

Has anyone succeded in setting this up to have Devise work with minitest?

1

1 Answers

15
votes

Add the following to your minitest_helper.rb file:

class MiniTest::Rails::ActionController::TestCase
  include Devise::TestHelpers
end