mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make driven_by
overridable
Sometimes we want to use rack_test partially instead of selenium for test speed: ```ruby class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: {url: "http://chrome:4444/wd/hub"} end class WithJavaScriptTest < ApplicationSystemTestCase end class WithoutJavaScriptTest < ApplicationSystemTestCase driven_by :rack_test end ``` In the abobe case, `WithoutJavaScriptTest` uses selenium because `SystemTestCase` calls superclass' driver on `#initialize` (`self.class.superclass.driver.use`). Using `class_attribute` can handle inherited `driven_by`.
This commit is contained in:
parent
5ac89b168b
commit
24e0fa7c4a
2 changed files with 13 additions and 6 deletions
|
@ -87,7 +87,7 @@ module ActionDispatch
|
|||
|
||||
def initialize(*) # :nodoc:
|
||||
super
|
||||
self.class.superclass.driver.use
|
||||
self.class.driver.use
|
||||
end
|
||||
|
||||
def self.start_application # :nodoc:
|
||||
|
@ -100,6 +100,8 @@ module ActionDispatch
|
|||
SystemTesting::Server.new.run
|
||||
end
|
||||
|
||||
class_attribute :driver, instance_accessor: false
|
||||
|
||||
# System Test configuration options
|
||||
#
|
||||
# The default settings are Selenium, using Chrome, with a screen size
|
||||
|
@ -113,13 +115,10 @@ module ActionDispatch
|
|||
#
|
||||
# driven_by :selenium, screen_size: [800, 800]
|
||||
def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400], options: {})
|
||||
@driver = SystemTesting::Driver.new(driver, using: using, screen_size: screen_size, options: options)
|
||||
self.driver = SystemTesting::Driver.new(driver, using: using, screen_size: screen_size, options: options)
|
||||
end
|
||||
|
||||
# Returns the driver object for the initialized system test
|
||||
def self.driver
|
||||
@driver ||= SystemTestCase.driven_by(:selenium)
|
||||
end
|
||||
driven_by :selenium
|
||||
end
|
||||
|
||||
SystemTestCase.start_application
|
||||
|
|
|
@ -6,6 +6,14 @@ class SetDriverToRackTestTest < DrivenByRackTest
|
|||
end
|
||||
end
|
||||
|
||||
class OverrideSeleniumSubclassToRackTestTest < DrivenBySeleniumWithChrome
|
||||
driven_by :rack_test
|
||||
|
||||
test "uses rack_test" do
|
||||
assert_equal :rack_test, Capybara.current_driver
|
||||
end
|
||||
end
|
||||
|
||||
class SetDriverToSeleniumTest < DrivenBySeleniumWithChrome
|
||||
test "uses selenium" do
|
||||
assert_equal :selenium, Capybara.current_driver
|
||||
|
|
Loading…
Reference in a new issue