I’m writing an rspec for my platform using the switch_user gem and I’m trying to write a single spec that work both with the selenium driver and the rack test driver. What I’ve got is the following:
login_as user
visit "/"
expect {
visit "/switch_user?scope_identifier=user_#{user2.id}"
}.to raise_error(ActionController::RoutingError, "Do not try to hack us.")
And this work perfectly fine when I run the spec with the rack_test driver, but when I run it with the selenium driver the test fails with:
2.1) Failure/Error:
expect {
visit "/switch_user?scope_identifier=user_#{user2.id}"
}.to raise_error(ActionController::RoutingError, "Do not try to hack us.")
expected ActionController::RoutingError with "Do not try to hack us." but nothing was raised
2.2) Failure/Error: raise ActionController::RoutingError, 'Do not try to hack us.' unless available?
ActionController::RoutingError:
Do not try to hack us.
[Screenshot Image]: /home/shadydealer/platform/tmp/screenshots/failures_r_spec_example_groups_switch_user_a_child_that_s_logged_in_on_it_s_own_cannot_switch_to_it_s_caregivers_account_460.png
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/switch_user-1.5.4/app/controllers/switch_user_controller.rb:36:in `developer_modes_only'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/actiontext-6.1.4/lib/action_text/rendering.rb:20:in `with_renderer'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/actiontext-6.1.4/lib/action_text/engine.rb:59:in `block (4 levels) in <class:Engine>'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/warden-1.2.9/lib/warden/manager.rb:36:in `block in call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/warden-1.2.9/lib/warden/manager.rb:34:in `catch'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/warden-1.2.9/lib/warden/manager.rb:34:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/tempfile_reaper.rb:15:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/etag.rb:27:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/conditional_get.rb:27:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:266:in `context'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:260:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/railties-6.1.4/lib/rails/rack/logger.rb:37:in `call_app'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/railties-6.1.4/lib/rails/rack/logger.rb:26:in `block in call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/railties-6.1.4/lib/rails/rack/logger.rb:26:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/railties-6.1.4/lib/rails/engine.rb:539:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/urlmap.rb:74:in `block in call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/urlmap.rb:58:in `each'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/urlmap.rb:58:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/rack-2.2.3/lib/rack/builder.rb:244:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/capybara-3.35.3/lib/capybara/server/middleware.rb:60:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/puma-5.4.0/lib/puma/configuration.rb:249:in `call'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/puma-5.4.0/lib/puma/request.rb:77:in `block in handle_request'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/puma-5.4.0/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/puma-5.4.0/lib/puma/request.rb:76:in `handle_request'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/puma-5.4.0/lib/puma/server.rb:440:in `process_client'
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/puma-5.4.0/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
# ------------------
# --- Caused by: ---
# Capybara::CapybaraError:
# Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true
# /home/shadydealer/.rvm/gems/ruby-2.7.4/gems/capybara-3.35.3/lib/capybara/session.rb:160:in `raise_server_error!'
So my question is:
Is there a way for me to write a singe spec that would run with both drivers or do I have to write 2 separate specs for each driver?