Skip to content

Instantly share code, notes, and snippets.

@arturictus
Created March 19, 2015 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturictus/a5a30fd78cd42f642e43 to your computer and use it in GitHub Desktop.
Save arturictus/a5a30fd78cd42f642e43 to your computer and use it in GitHub Desktop.
Rspec-capybara login with warden
# spec/rails_helper.rb
# add to your rails_helper inside the
RSpec.configure do |config|
config.around(:each, type: :request) do |example|
Warden.test_mode!
example.run
Warden.test_reset!
end
end
# spec/support/warden_login.rb
def warden_login(factory = :admin_user, opts = {})
let(:admin_user) { create(factory, opts) }
around(:each) do |example|
login_as(admin_user, :scope => :admin_user)
example.run
logout(:admin_user)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment