Mascote

notes to self.

Solving 'Undefined Method Authenticate' When Using MiniTest and Devise in Rails 4.2

If you are using methods like user_signed_in? inside your controllers and receiving errors like those when running MiniTest:

1
ActionView::Template::Error: undefined method `authenticate' for nil:NilClass

or

1
ArgumentError: uncaught throw :warden

just reopen ActionController::TestCase and include the Devise::TestHelpers putting this at the end of your test_helper.rb file:

1
2
3
class ActionController::TestCase
  include Devise::TestHelpers
end

No more errors!

tip: you can use the sign_in helper provided by Devise to use inside your controller tests.