aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/system_test_case.rb
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2017-03-06 12:33:34 -0500
committereileencodes <eileencodes@gmail.com>2017-03-09 10:52:05 -0500
commit7c9af60e5c26941dc9ec6a263f5fc5fe10050cba (patch)
tree649265a1a13d65419fa9db104ed1e1cd71e84f4e /actionpack/lib/action_dispatch/system_test_case.rb
parent4dbebe487df54e8684183f3b3154639a77d8deaa (diff)
downloadrails-7c9af60e5c26941dc9ec6a263f5fc5fe10050cba.tar.gz
rails-7c9af60e5c26941dc9ec6a263f5fc5fe10050cba.tar.bz2
rails-7c9af60e5c26941dc9ec6a263f5fc5fe10050cba.zip
Call system test driver per-instance rather than globally
Previously the system test subclasses would call `driven_by` when the app booted and not again when the test was initialized which resulted in the driver from whichever class was called last to be used in tests. In rails/rails#28144 the `driven_by` method was changed to run `use` on setup and `reset` on teardown. While this was a viable fix this really pointed to the problem that system test `driven_by` was a global setting, rather than a per-class setting. To alieviate this problem calling the driver should be done on an instance level, rather than on the global level. I added an `initialize` method to `SystemTestCase` which will call `use` on the superclass driver. Running the server has been moved to `start_application` so that it only needs to be called once on boot and no options from `driven_by` were being passed to it. This required a largish rewrite of the tests. Each test needs to utilize the subclass so that it can properly test the drivers. `ActionDispatch::SystemTestCase` shouldn't be called directly anymore.
Diffstat (limited to 'actionpack/lib/action_dispatch/system_test_case.rb')
-rw-r--r--actionpack/lib/action_dispatch/system_test_case.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/system_test_case.rb b/actionpack/lib/action_dispatch/system_test_case.rb
index d872fca6bf..1bf47d2556 100644
--- a/actionpack/lib/action_dispatch/system_test_case.rb
+++ b/actionpack/lib/action_dispatch/system_test_case.rb
@@ -83,12 +83,19 @@ module ActionDispatch
include SystemTesting::TestHelpers::SetupAndTeardown
include SystemTesting::TestHelpers::ScreenshotHelper
+ def initialize(*) # :nodoc:
+ super
+ self.class.superclass.driver.use
+ end
+
def self.start_application # :nodoc:
Capybara.app = Rack::Builder.new do
map "/" do
run Rails.application
end
end
+
+ SystemTesting::Server.new.run
end
# System Test configuration options
@@ -104,12 +111,12 @@ module ActionDispatch
#
# driven_by :selenium, screen_size: [800, 800]
def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400])
- driver = SystemTesting::Driver.new(driver, using: using, screen_size: screen_size)
-
- setup { driver.use }
- teardown { driver.reset }
+ @driver = SystemTesting::Driver.new(driver, using: using, screen_size: screen_size)
+ end
- SystemTesting::Server.new.run
+ # Returns the driver object for the initialized system test
+ def self.driver
+ @driver ||= SystemTestCase.driven_by(:selenium)
end
end