From 385a7507f6525d9b2d1e23bef0bb2e6fe5ad0c97 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Thu, 18 Sep 2014 14:38:14 -0700 Subject: [PATCH] Use Rack::Lock to prevent concurrency when eager_load is false --- lib/capybara/rails.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/capybara/rails.rb b/lib/capybara/rails.rb index e9f4cd5c..26bc36e2 100644 --- a/lib/capybara/rails.rb +++ b/lib/capybara/rails.rb @@ -2,6 +2,12 @@ require 'capybara' require 'capybara/dsl' Capybara.app = Rack::Builder.new do + # Work around an issue where rails allows concurrency in test mode even though eager_load + # is false which can cause an issue with constant loading + if Gem::Version.new(Rails.version) >= Gem::Version.new("4.0") + use Rack::Lock unless Rails.application.config.eager_load || Rails.application.middleware.include?(Rack::Lock) + end + map "/" do if Gem::Version.new(Rails.version) >= Gem::Version.new("3.0") run Rails.application