Capybara uncaught throw :warden

Skip to first unread message

Andre Roy

May 19, 2022, 7:14:50 PMMay 19
to Capybara
I am trying to write integration test for a rails app that uses Devise for authentication. I have setup capybara but when I run the test, I get the error uncaught throw :warden. I have implemented a series of solution I saw on StackOverflow but none worked for me. The recent solution I tried was to use Warden to simulate authentication, also making sure that the user is confirmed but the same error keeps coming up. Any idea on how to solve this issue?

Christopher Irish

May 19, 2022, 11:37:17 PMMay 19
to Capybara
Without seeing code it's hard to help.  

But I assume login works running in development, correct?  If you're getting that error in dev then it's not your test.

And in that case, I'd undo whatever "series of solutions" you tried, and restart using just the README for the version of Devise you have installed.

But if dev works and it is your test, are you visiting the page, filling in the form, and submitting it successfully?

Otherwise, share some code and you'll get more useful help

Andre Roy

May 23, 2022, 1:31:39 PMMay 23
Hello Christopher, thanks for your response. Sorry for the late response, I was not on sit. Here is the configuration in my rails_helper file.

# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/rspec'

# Add additional requires below this line. Rails is not loaded until this point!

Capybara.configure do |config|
config.run_server = true

Capybara.server = :puma
Capybara.javascript_driver = :selenium

rescue ActiveRecord::PendingMigrationError => e
puts e.to_s.strip
exit 1
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

config.use_transactional_fixtures = false


# Filter lines from Rails gems in backtraces.

config.include FactoryBot::Syntax::Methods

# Database cleaner configurations
config.before(:suite) { DatabaseCleaner.clean_with(:truncation) }
config.before(:each) { DatabaseCleaner.strategy = :transaction }
config.before(:each, js: true) { DatabaseCleaner.strategy = :truncation }
config.before(:each) { DatabaseCleaner.start }
config.after(:each) { DatabaseCleaner.clean }

config.include Warden::Test::Helpers


Here is the sample test that I am trying to run

require 'rails_helper'

RSpec.feature "Account interaction", type: :feature, js: true do
let(:user) { build(:user, username: "ruynohub1", suspend: false, email: "", password: "rynohub12345", password_confirmation: "rynohub12345")}
let(:supervisor) { build(:user) }
before :each do false)
user.supervisor =
user.account_type = "Call Listener"
5.times { create(:account) }

context "When visiting account index page" do
it "account page should be accessible" do
login_as(user, :scope => :user)
visit root_path

It's worth noting that I am using Warden to bypass devise authentication.
Here is a section of the error that pops up.

Error during failsafe response: uncaught throw :warden

  /Users/administrator/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/warden-1.2.9/lib/warden/proxy.rb:134:in `throw'

  /Users/administrator/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/warden-1.2.9/lib/warden/proxy.rb:134:in `authenticate!'

  /Users/administrator/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/devise-4.8.1/lib/devise/controllers/helpers.rb:118:in `authenticate_user!'

When running the test, firefox pops up and I see the running. The test breaks with the above error when I visit any link even after setting up Warden.
Please let me know if you need any further information in other to help me out thanks.
You received this message because you are subscribed to a topic in the Google Groups "Capybara" group.
To unsubscribe from this topic, visit
To unsubscribe from this group and all its topics, send an email to
To view this discussion on the web visit

Andre Roy

May 26, 2022, 5:02:00 PMMay 26
Reply all
Reply to author
0 new messages