I\'m using Rails 5, and Devise 3.5.1.
Going through a nice (older) book about creating/testing an API, which uses Devise authentication. It was written before Rails
This works for vanilla Rails 4 MiniTest
test\controllers\users_controller_test.rb
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
include Warden::Test::Helpers
include Devise::Test::ControllerHelpers
setup do
# https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara
# @user = users(:admin)
# sign_in @user
end
teardown do
Warden.test_reset!
end
test "login as admin" do
@user = users :admin
sign_in @user
get :dashboard
assert_redirected_to admin_dashboard_path
end
end
In the spec_helper.rb
add:
config.include Devise::Test::ControllerHelpers, :type => :controller
You could add the following to your rails_helper
:
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
end
This will include Devise::Test::ControllerHelpers
module in all :controller
specs.