Login Devise user in Capybara tests
11 March 2022 (Updated 23 April 2022)
These instructions assume you’ve implemented authentication using Devise and you’re using RSpec & Capybara to write your feature tests.
Include Warden test helpers
Create a spec/support/devise.rb
file with the following configuration:
Include this support file in spec/rails_helper.rb
:
Use the login_as
helper method
Now, you can use the login_as
method to log in any ActiveRecord user like so:
See Devise’s wiki page for more info on testing with Capybara.
Tagged:
Rails testing
Thanks for your comment . Once it's approved, it will appear here.
Leave a comment