Rails controller spec helpers for Warden. If you're using Warden without Devise in rails, due to how ActionController sets up the test environment, custom test setup code is necessary.
# Gemfile
group :test do
gem 'warden-rspec-rails'
end
# spec_helper.rb
RSpec.configure do |c|
c.include Warden::Test::ControllerHelpers, type: :controller
end
This will define helper methods in controller tests that you can use to manage authentication, such as:
warden
: Access theWarden::Proxy
.login_as
: Same as theWarden::Test::Helpers
login_as
method.logout
: Same as theWarden::Test::Helpers
logout
method.unlogin
: Removes the user(s) from the logged-in list, but leaves the session value so the user can be fetched on access.