Capybara uncaught throw :warden

19 views
Skip to first unread message

Andre Roy

unread,
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

unread,
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

unread,
May 23, 2022, 1:31:39 PMMay 23
to ruby-c...@googlegroups.com
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
end

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

begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
puts e.to_s.strip
exit 1
end
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

config.infer_spec_type_from_file_location!

# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!

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

end


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: "ryn...@gmail.com", password: "rynohub12345", password_confirmation: "rynohub12345")}
let(:supervisor) { build(:user) }
before :each do
supervisor.save(validate: false)
user.supervisor = supervisor.id
user.account_type = "Call Listener"
user.save
5.times { create(:account) }
end


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

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 https://groups.google.com/d/topic/ruby-capybara/Dg_Gle5FcIA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ruby-capybar...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-capybara/ef6a4b4a-e1d2-4511-985a-de83239ab26an%40googlegroups.com.

Andre Roy

unread,
May 26, 2022, 5:02:00 PMMay 26
to ruby-c...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages