Permalink
Browse files

Merge pull request #28144 from lucasmazza/lm-system-test-driven-by

Change `SystemTestCase.driven_by` to use `setup`/`teardown` hooks
  • Loading branch information...
eileencodes committed Feb 24, 2017
2 parents aa56dc2 + 704853b commit 87b2b6c5124732ff709b8e1900a99ba0a08f6982
@@ -105,9 +105,16 @@ def self.start_application # :nodoc:
#
# driven_by :selenium, screen_size: [800, 800]
def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400])
- SystemTesting::Driver.new(driver).run
+ driver = if selenium?(driver)
+ SystemTesting::Browser.new(using, screen_size)
+ else
+ SystemTesting::Driver.new(driver)
+ end
+
+ setup { driver.use }
+ teardown { driver.reset }
+
SystemTesting::Server.new.run
- SystemTesting::Browser.new(using, screen_size).run if selenium?(driver)
end
def self.selenium?(driver) # :nodoc:
@@ -1,14 +1,17 @@
+require "action_dispatch/system_testing/driver"
+
module ActionDispatch
module SystemTesting
- class Browser # :nodoc:
+ class Browser < Driver # :nodoc:
def initialize(name, screen_size)
+ super(name)
@name = name
@screen_size = screen_size
end
- def run
+ def use
register
- setup
+ super
end
private
@@ -19,10 +22,6 @@ def register
end
end
end
-
- def setup
- Capybara.default_driver = @name.to_sym
- end
end
end
end
@@ -5,14 +5,14 @@ def initialize(name)
@name = name
end
- def run
- register
+ def use
+ @current = Capybara.current_driver
+ Capybara.current_driver = @name
end
- private
- def register
- Capybara.default_driver = @name
- end
+ def reset
+ Capybara.current_driver = @current
+ end
end
end
end
@@ -1,21 +1,23 @@
require "abstract_unit"
-class SystemTestCaseTest < ActiveSupport::TestCase
- test "driven_by sets Capybara's default driver to poltergeist" do
- ActionDispatch::SystemTestCase.driven_by :poltergeist
-
- assert_equal :poltergeist, Capybara.default_driver
+class DrivenByCaseTestTest < ActiveSupport::TestCase
+ test "selenium? returns false if driver is poltergeist" do
+ assert_not ActionDispatch::SystemTestCase.selenium?(:poltergeist)
end
+end
- test "driven_by sets Capybara's drivers respectively" do
- ActionDispatch::SystemTestCase.driven_by :selenium, using: :chrome
+class DrivenByRackTestTest < ActionDispatch::SystemTestCase
+ driven_by :rack_test
- assert_includes Capybara.drivers, :selenium
- assert_includes Capybara.drivers, :chrome
- assert_equal :chrome, Capybara.default_driver
+ test "uses rack_test" do
+ assert_equal :rack_test, Capybara.current_driver
end
+end
- test "selenium? returns false if driver is poltergeist" do
- assert_not ActionDispatch::SystemTestCase.selenium?(:poltergeist)
+class DrivenBySeleniumWithChromeTest < ActionDispatch::SystemTestCase
+ driven_by :selenium, using: :chrome
+
+ test "uses selenium" do
+ assert_equal :chrome, Capybara.current_driver
end
end

0 comments on commit 87b2b6c

Please sign in to comment.