Skip to content

Capybara.reset_session! should be called before requests are blocked

capybara/rspec.rb already calls Capybara.reset_sessions! in an after hook, but block_and_wait_for_requests_complete is called before it so by calling it explicitely here, we prevent any new requests from being fired.

I believe, when block_and_wait_for_requests_complete was introduced, it also had the side-effect of not navigating to the blank page anymore prior to blocking any new requests, thus we actually opened the door for different transient failures...

I believe the ultimate solution is as follows:

diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb
index c34e76fa72..4aa81a0355 100644
--- a/spec/support/capybara.rb
+++ b/spec/support/capybara.rb
@@ -35,4 +35,13 @@ RSpec.configure do |config|
     TestEnv.eager_load_driver_server
     $capybara_server_already_started = true
   end
+
+  config.after(:each, :js) do
+    Capybara.reset_sessions!
+    block_and_wait_for_requests_complete
+  end
 end
diff --git a/spec/support/wait_for_requests.rb b/spec/support/wait_for_requests.rb
index 1cbe609c0e..d19d01f2d6 100644
--- a/spec/support/wait_for_requests.rb
+++ b/spec/support/wait_for_requests.rb
@@ -53,9 +54,3 @@ module WaitForRequests
     Capybara.current_driver == Capybara.javascript_driver
   end
 end
-
-RSpec.configure do |config|
-  config.after(:each, :js) do
-    block_and_wait_for_requests_complete
-  end
-end