From 9730b1dba6d1bb9684a54915ac3735d9c0eade26 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 27 Aug 2016 16:48:24 -0400 Subject: Add tests for system testing * Adds test case test * Adds driver adapter test * Adds tests for capybara seleium driver (testing the settings not actually opening the browser to test capybara w/ selenium because that would so so so slow) * Adds tests for rack test driver * Adds tests for generators --- actionpack/test/abstract_unit.rb | 1 + .../capybara_rack_test_driver_test.rb | 26 ++++++++++ .../capybara_selenium_driver_test.rb | 58 ++++++++++++++++++++++ .../test/system_testing/driver_adapter_test.rb | 19 +++++++ 4 files changed, 104 insertions(+) create mode 100644 actionpack/test/system_testing/capybara_rack_test_driver_test.rb create mode 100644 actionpack/test/system_testing/capybara_selenium_driver_test.rb create mode 100644 actionpack/test/system_testing/driver_adapter_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 459b0d6c54..3b35af6d3a 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -33,6 +33,7 @@ require "action_view/testing/resolvers" require "action_dispatch" require "active_support/dependencies" require "active_model" +require "system_test_case" require "pp" # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late diff --git a/actionpack/test/system_testing/capybara_rack_test_driver_test.rb b/actionpack/test/system_testing/capybara_rack_test_driver_test.rb new file mode 100644 index 0000000000..0f037760d3 --- /dev/null +++ b/actionpack/test/system_testing/capybara_rack_test_driver_test.rb @@ -0,0 +1,26 @@ +require 'abstract_unit' + +class CapybaraRackTestDriverTest < ActiveSupport::TestCase + def test_default_driver_adapter + assert_kind_of SystemTesting::DriverAdapters::CapybaraRackTestDriver, Rails::SystemTestCase.driver + end + + def test_default_settings + assert_equal 'Capybara', Rails::SystemTestCase.driver.useragent + end + + def test_setting_useragent + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new( + useragent: 'x' + ) + assert_equal 'x', Rails::SystemTestCase.driver.useragent + end + + def test_does_not_accept_nonsense_kwargs + assert_raises ArgumentError do + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new( + made_up_arg: 'x' + ) + end + end +end diff --git a/actionpack/test/system_testing/capybara_selenium_driver_test.rb b/actionpack/test/system_testing/capybara_selenium_driver_test.rb new file mode 100644 index 0000000000..6357b35aa6 --- /dev/null +++ b/actionpack/test/system_testing/capybara_selenium_driver_test.rb @@ -0,0 +1,58 @@ +require 'abstract_unit' + +class CapybaraSeleniumDriverTest < ActiveSupport::TestCase + def setup + Rails::SystemTestCase.driver = :capybara_selenium_driver + end + + def test_setting_driver_adapter_to_selenium + assert_kind_of SystemTesting::DriverAdapters::CapybaraSeleniumDriver, Rails::SystemTestCase.driver + end + + def test_default_settings + assert_equal :chrome, Rails::SystemTestCase.driver.browser + assert_equal :puma, Rails::SystemTestCase.driver.server + assert_equal 28100, Rails::SystemTestCase.driver.port + assert_equal [1400,1400], Rails::SystemTestCase.driver.screen_size + end + + def test_setting_browser + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new( + browser: :firefox + ) + + assert_equal :firefox, Rails::SystemTestCase.driver.browser + end + + def test_setting_server + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new( + server: :webrick + ) + + assert_equal :webrick, Rails::SystemTestCase.driver.server + end + + def test_setting_port + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new( + port: 3000 + ) + + assert_equal 3000, Rails::SystemTestCase.driver.port + end + + def test_setting_screen_size + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new( + screen_size: [ 800, 800 ] + ) + + assert_equal [ 800, 800 ], Rails::SystemTestCase.driver.screen_size + end + + def test_does_not_accept_nonsense_kwargs + assert_raises ArgumentError do + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new( + made_up_arg: 'x' + ) + end + end +end diff --git a/actionpack/test/system_testing/driver_adapter_test.rb b/actionpack/test/system_testing/driver_adapter_test.rb new file mode 100644 index 0000000000..bfbeaa63a2 --- /dev/null +++ b/actionpack/test/system_testing/driver_adapter_test.rb @@ -0,0 +1,19 @@ +require 'abstract_unit' + +class DriverAdapterTest < ActiveSupport::TestCase + test 'only registered adapters are accepted' do + assert_raises(NameError) do + Rails::SystemTestCase.driver = :whatever + end + + assert_nothing_raised do + Rails::SystemTestCase.driver = :capybara_selenium_driver + end + end + + test 'settings can only be used for the appropriate adapter' do + assert_raises(ArgumentError) do + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new(something: 'test') + end + end +end -- cgit v1.2.3 From f482eddbeff9fe3d0dc6cdaa9a4b53df839f667c Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 1 Oct 2016 11:17:43 -0400 Subject: Reconfigure how the drivers work This removes the useless Rack Test Driver that Rails was providing and moves to a shim like approach for default adapters. If someone wants to use one of the default Capybara Drivers then we will initialize a new `CapybaraDriver` that simply sets the default driver. Rails though is much more opinionated than Capybara and to make system testing a "works out of the box" framework in Rails we have the `RailsSeleniumDriver`. This driver sets defaults that Rails deems important for selenium testing. The purpose of this is to simply add a test and it just works. --- .../test/system_testing/capybara_driver_test.rb | 10 ++++ .../capybara_rack_test_driver_test.rb | 26 ---------- .../capybara_selenium_driver_test.rb | 58 ---------------------- .../test/system_testing/driver_adapter_test.rb | 8 +-- .../system_testing/rails_selenium_driver_test.rb | 58 ++++++++++++++++++++++ 5 files changed, 69 insertions(+), 91 deletions(-) create mode 100644 actionpack/test/system_testing/capybara_driver_test.rb delete mode 100644 actionpack/test/system_testing/capybara_rack_test_driver_test.rb delete mode 100644 actionpack/test/system_testing/capybara_selenium_driver_test.rb create mode 100644 actionpack/test/system_testing/rails_selenium_driver_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/system_testing/capybara_driver_test.rb b/actionpack/test/system_testing/capybara_driver_test.rb new file mode 100644 index 0000000000..b409fdfab0 --- /dev/null +++ b/actionpack/test/system_testing/capybara_driver_test.rb @@ -0,0 +1,10 @@ +require 'abstract_unit' + +class CapybaraDriverTest < ActiveSupport::TestCase + def test_setting_useragent + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraDriver.new( + :rack_test + ) + assert_equal :rack_test, Rails::SystemTestCase.driver.name + end +end diff --git a/actionpack/test/system_testing/capybara_rack_test_driver_test.rb b/actionpack/test/system_testing/capybara_rack_test_driver_test.rb deleted file mode 100644 index 0f037760d3..0000000000 --- a/actionpack/test/system_testing/capybara_rack_test_driver_test.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'abstract_unit' - -class CapybaraRackTestDriverTest < ActiveSupport::TestCase - def test_default_driver_adapter - assert_kind_of SystemTesting::DriverAdapters::CapybaraRackTestDriver, Rails::SystemTestCase.driver - end - - def test_default_settings - assert_equal 'Capybara', Rails::SystemTestCase.driver.useragent - end - - def test_setting_useragent - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new( - useragent: 'x' - ) - assert_equal 'x', Rails::SystemTestCase.driver.useragent - end - - def test_does_not_accept_nonsense_kwargs - assert_raises ArgumentError do - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new( - made_up_arg: 'x' - ) - end - end -end diff --git a/actionpack/test/system_testing/capybara_selenium_driver_test.rb b/actionpack/test/system_testing/capybara_selenium_driver_test.rb deleted file mode 100644 index 6357b35aa6..0000000000 --- a/actionpack/test/system_testing/capybara_selenium_driver_test.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'abstract_unit' - -class CapybaraSeleniumDriverTest < ActiveSupport::TestCase - def setup - Rails::SystemTestCase.driver = :capybara_selenium_driver - end - - def test_setting_driver_adapter_to_selenium - assert_kind_of SystemTesting::DriverAdapters::CapybaraSeleniumDriver, Rails::SystemTestCase.driver - end - - def test_default_settings - assert_equal :chrome, Rails::SystemTestCase.driver.browser - assert_equal :puma, Rails::SystemTestCase.driver.server - assert_equal 28100, Rails::SystemTestCase.driver.port - assert_equal [1400,1400], Rails::SystemTestCase.driver.screen_size - end - - def test_setting_browser - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new( - browser: :firefox - ) - - assert_equal :firefox, Rails::SystemTestCase.driver.browser - end - - def test_setting_server - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new( - server: :webrick - ) - - assert_equal :webrick, Rails::SystemTestCase.driver.server - end - - def test_setting_port - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new( - port: 3000 - ) - - assert_equal 3000, Rails::SystemTestCase.driver.port - end - - def test_setting_screen_size - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new( - screen_size: [ 800, 800 ] - ) - - assert_equal [ 800, 800 ], Rails::SystemTestCase.driver.screen_size - end - - def test_does_not_accept_nonsense_kwargs - assert_raises ArgumentError do - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new( - made_up_arg: 'x' - ) - end - end -end diff --git a/actionpack/test/system_testing/driver_adapter_test.rb b/actionpack/test/system_testing/driver_adapter_test.rb index bfbeaa63a2..220a755bd3 100644 --- a/actionpack/test/system_testing/driver_adapter_test.rb +++ b/actionpack/test/system_testing/driver_adapter_test.rb @@ -7,13 +7,7 @@ class DriverAdapterTest < ActiveSupport::TestCase end assert_nothing_raised do - Rails::SystemTestCase.driver = :capybara_selenium_driver - end - end - - test 'settings can only be used for the appropriate adapter' do - assert_raises(ArgumentError) do - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new(something: 'test') + Rails::SystemTestCase.driver = :rack_test end end end diff --git a/actionpack/test/system_testing/rails_selenium_driver_test.rb b/actionpack/test/system_testing/rails_selenium_driver_test.rb new file mode 100644 index 0000000000..c239444838 --- /dev/null +++ b/actionpack/test/system_testing/rails_selenium_driver_test.rb @@ -0,0 +1,58 @@ +require 'abstract_unit' + +class RailsSeleniumDriverTest < ActiveSupport::TestCase + def setup + Rails::SystemTestCase.driver = :rails_selenium_driver + end + + def test_default_driver_adapter + assert_kind_of SystemTesting::DriverAdapters::RailsSeleniumDriver, Rails::SystemTestCase.driver + end + + def test_default_settings + assert_equal :chrome, Rails::SystemTestCase.driver.browser + assert_equal :puma, Rails::SystemTestCase.driver.server + assert_equal 28100, Rails::SystemTestCase.driver.port + assert_equal [1400,1400], Rails::SystemTestCase.driver.screen_size + end + + def test_setting_browser + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( + browser: :firefox + ) + + assert_equal :firefox, Rails::SystemTestCase.driver.browser + end + + def test_setting_server + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( + server: :webrick + ) + + assert_equal :webrick, Rails::SystemTestCase.driver.server + end + + def test_setting_port + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( + port: 3000 + ) + + assert_equal 3000, Rails::SystemTestCase.driver.port + end + + def test_setting_screen_size + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( + screen_size: [ 800, 800 ] + ) + + assert_equal [ 800, 800 ], Rails::SystemTestCase.driver.screen_size + end + + def test_does_not_accept_nonsense_kwargs + assert_raises ArgumentError do + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( + made_up_arg: 'x' + ) + end + end +end -- cgit v1.2.3 From e9127f7aa082986952ffcc8331b675a3a99c3a83 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 2 Oct 2016 15:22:27 -0400 Subject: Add support for screenshots This change adds support, tests, and documentation for the screenshot helper. If taking screenshots is supported by the driver (for example Rack Test doesn't support screenshots) then a screenshot will be taken if the test fails. --- .../test/system_testing/screenshot_helper_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 actionpack/test/system_testing/screenshot_helper_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/system_testing/screenshot_helper_test.rb b/actionpack/test/system_testing/screenshot_helper_test.rb new file mode 100644 index 0000000000..8bf2d0c8d0 --- /dev/null +++ b/actionpack/test/system_testing/screenshot_helper_test.rb @@ -0,0 +1,20 @@ +require 'abstract_unit' + +class ScreenshotHelperTest < ActiveSupport::TestCase + def test_driver_support_for_screenshots + Rails::SystemTestCase.driver = :rails_selenium_driver + assert Rails::SystemTestCase.driver.supports_screenshots? + + Rails::SystemTestCase.driver = :rack_test + assert_not Rails::SystemTestCase.driver.supports_screenshots? + + Rails::SystemTestCase.driver = :selenium + assert Rails::SystemTestCase.driver.supports_screenshots? + + Rails::SystemTestCase.driver = :webkit + assert Rails::SystemTestCase.driver.supports_screenshots? + + Rails::SystemTestCase.driver = :poltergeist + assert Rails::SystemTestCase.driver.supports_screenshots? + end +end -- cgit v1.2.3 From c83e6d36dd13baa8b8cb48ce1c628788a2456d21 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 2 Oct 2016 17:37:57 -0400 Subject: Refactor so all drivers use Puma by default Puma is the default webserver of Rails. Because of this it doesn't make sense to run tests in Webkit if the default server is Puma. Here I've refactored the webserver to be it's own standalone module so it can be shared between Rails' selenium default driver and Capybara's defaut drivers. --- .../test/system_testing/capybara_driver_test.rb | 35 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/system_testing/capybara_driver_test.rb b/actionpack/test/system_testing/capybara_driver_test.rb index b409fdfab0..a6be63ba7f 100644 --- a/actionpack/test/system_testing/capybara_driver_test.rb +++ b/actionpack/test/system_testing/capybara_driver_test.rb @@ -1,10 +1,39 @@ require 'abstract_unit' class CapybaraDriverTest < ActiveSupport::TestCase - def test_setting_useragent + def setup + Rails::SystemTestCase.driver = :poltergeist + end + + def test_default_driver_adapter + assert_kind_of SystemTesting::DriverAdapters::CapybaraDriver, Rails::SystemTestCase.driver + end + + def test_default_settings + assert_equal :poltergeist, Rails::SystemTestCase.driver.name + assert_equal :puma, Rails::SystemTestCase.driver.server + assert_equal 28100, Rails::SystemTestCase.driver.port + end + + def test_setting_driver + Rails::SystemTestCase.driver = :webkit + + assert_equal :webkit, Rails::SystemTestCase.driver.name + end + + def test_setting_server Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraDriver.new( - :rack_test + server: :webrick ) - assert_equal :rack_test, Rails::SystemTestCase.driver.name + + assert_equal :webrick, Rails::SystemTestCase.driver.server + end + + def test_setting_port + Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraDriver.new( + port: 3000 + ) + + assert_equal 3000, Rails::SystemTestCase.driver.port end end -- cgit v1.2.3 From a21e18d5080a2c4808330271885f5664a725d3f3 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Tue, 4 Oct 2016 08:48:21 -0400 Subject: Appease Rubocop Rubocop / code climate don't like single quotes and prefer doubles. --- actionpack/test/system_testing/capybara_driver_test.rb | 2 +- actionpack/test/system_testing/driver_adapter_test.rb | 4 ++-- actionpack/test/system_testing/rails_selenium_driver_test.rb | 4 ++-- actionpack/test/system_testing/screenshot_helper_test.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/system_testing/capybara_driver_test.rb b/actionpack/test/system_testing/capybara_driver_test.rb index a6be63ba7f..129fe95f25 100644 --- a/actionpack/test/system_testing/capybara_driver_test.rb +++ b/actionpack/test/system_testing/capybara_driver_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class CapybaraDriverTest < ActiveSupport::TestCase def setup diff --git a/actionpack/test/system_testing/driver_adapter_test.rb b/actionpack/test/system_testing/driver_adapter_test.rb index 220a755bd3..035d018adf 100644 --- a/actionpack/test/system_testing/driver_adapter_test.rb +++ b/actionpack/test/system_testing/driver_adapter_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' +require "abstract_unit" class DriverAdapterTest < ActiveSupport::TestCase - test 'only registered adapters are accepted' do + test "only registered adapters are accepted" do assert_raises(NameError) do Rails::SystemTestCase.driver = :whatever end diff --git a/actionpack/test/system_testing/rails_selenium_driver_test.rb b/actionpack/test/system_testing/rails_selenium_driver_test.rb index c239444838..25fc6ca097 100644 --- a/actionpack/test/system_testing/rails_selenium_driver_test.rb +++ b/actionpack/test/system_testing/rails_selenium_driver_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class RailsSeleniumDriverTest < ActiveSupport::TestCase def setup @@ -51,7 +51,7 @@ class RailsSeleniumDriverTest < ActiveSupport::TestCase def test_does_not_accept_nonsense_kwargs assert_raises ArgumentError do Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( - made_up_arg: 'x' + made_up_arg: "x" ) end end diff --git a/actionpack/test/system_testing/screenshot_helper_test.rb b/actionpack/test/system_testing/screenshot_helper_test.rb index 8bf2d0c8d0..8060c499df 100644 --- a/actionpack/test/system_testing/screenshot_helper_test.rb +++ b/actionpack/test/system_testing/screenshot_helper_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class ScreenshotHelperTest < ActiveSupport::TestCase def test_driver_support_for_screenshots -- cgit v1.2.3 From 5bf0aa6745db27c45c0778f9f6e9046f9ee9fb94 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 6 Nov 2016 18:55:15 -0500 Subject: Turn system testing into it's own gem and rename Renames `Rails::SystemTestCase` to `ActionSystemTest` and moves it to a gem under the Rails name. We need to name the class `ActionSystemTestCase` because the gem expects a module but tests themselves expect a class. Adds MIT-LICENSE, CHANGELOG, and README for the future. --- actionpack/test/abstract_unit.rb | 1 - .../test/system_testing/capybara_driver_test.rb | 39 --------------- .../test/system_testing/driver_adapter_test.rb | 13 ----- .../system_testing/rails_selenium_driver_test.rb | 58 ---------------------- .../test/system_testing/screenshot_helper_test.rb | 20 -------- 5 files changed, 131 deletions(-) delete mode 100644 actionpack/test/system_testing/capybara_driver_test.rb delete mode 100644 actionpack/test/system_testing/driver_adapter_test.rb delete mode 100644 actionpack/test/system_testing/rails_selenium_driver_test.rb delete mode 100644 actionpack/test/system_testing/screenshot_helper_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 3b35af6d3a..459b0d6c54 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -33,7 +33,6 @@ require "action_view/testing/resolvers" require "action_dispatch" require "active_support/dependencies" require "active_model" -require "system_test_case" require "pp" # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late diff --git a/actionpack/test/system_testing/capybara_driver_test.rb b/actionpack/test/system_testing/capybara_driver_test.rb deleted file mode 100644 index 129fe95f25..0000000000 --- a/actionpack/test/system_testing/capybara_driver_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "abstract_unit" - -class CapybaraDriverTest < ActiveSupport::TestCase - def setup - Rails::SystemTestCase.driver = :poltergeist - end - - def test_default_driver_adapter - assert_kind_of SystemTesting::DriverAdapters::CapybaraDriver, Rails::SystemTestCase.driver - end - - def test_default_settings - assert_equal :poltergeist, Rails::SystemTestCase.driver.name - assert_equal :puma, Rails::SystemTestCase.driver.server - assert_equal 28100, Rails::SystemTestCase.driver.port - end - - def test_setting_driver - Rails::SystemTestCase.driver = :webkit - - assert_equal :webkit, Rails::SystemTestCase.driver.name - end - - def test_setting_server - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraDriver.new( - server: :webrick - ) - - assert_equal :webrick, Rails::SystemTestCase.driver.server - end - - def test_setting_port - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraDriver.new( - port: 3000 - ) - - assert_equal 3000, Rails::SystemTestCase.driver.port - end -end diff --git a/actionpack/test/system_testing/driver_adapter_test.rb b/actionpack/test/system_testing/driver_adapter_test.rb deleted file mode 100644 index 035d018adf..0000000000 --- a/actionpack/test/system_testing/driver_adapter_test.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "abstract_unit" - -class DriverAdapterTest < ActiveSupport::TestCase - test "only registered adapters are accepted" do - assert_raises(NameError) do - Rails::SystemTestCase.driver = :whatever - end - - assert_nothing_raised do - Rails::SystemTestCase.driver = :rack_test - end - end -end diff --git a/actionpack/test/system_testing/rails_selenium_driver_test.rb b/actionpack/test/system_testing/rails_selenium_driver_test.rb deleted file mode 100644 index 25fc6ca097..0000000000 --- a/actionpack/test/system_testing/rails_selenium_driver_test.rb +++ /dev/null @@ -1,58 +0,0 @@ -require "abstract_unit" - -class RailsSeleniumDriverTest < ActiveSupport::TestCase - def setup - Rails::SystemTestCase.driver = :rails_selenium_driver - end - - def test_default_driver_adapter - assert_kind_of SystemTesting::DriverAdapters::RailsSeleniumDriver, Rails::SystemTestCase.driver - end - - def test_default_settings - assert_equal :chrome, Rails::SystemTestCase.driver.browser - assert_equal :puma, Rails::SystemTestCase.driver.server - assert_equal 28100, Rails::SystemTestCase.driver.port - assert_equal [1400,1400], Rails::SystemTestCase.driver.screen_size - end - - def test_setting_browser - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( - browser: :firefox - ) - - assert_equal :firefox, Rails::SystemTestCase.driver.browser - end - - def test_setting_server - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( - server: :webrick - ) - - assert_equal :webrick, Rails::SystemTestCase.driver.server - end - - def test_setting_port - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( - port: 3000 - ) - - assert_equal 3000, Rails::SystemTestCase.driver.port - end - - def test_setting_screen_size - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( - screen_size: [ 800, 800 ] - ) - - assert_equal [ 800, 800 ], Rails::SystemTestCase.driver.screen_size - end - - def test_does_not_accept_nonsense_kwargs - assert_raises ArgumentError do - Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::RailsSeleniumDriver.new( - made_up_arg: "x" - ) - end - end -end diff --git a/actionpack/test/system_testing/screenshot_helper_test.rb b/actionpack/test/system_testing/screenshot_helper_test.rb deleted file mode 100644 index 8060c499df..0000000000 --- a/actionpack/test/system_testing/screenshot_helper_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "abstract_unit" - -class ScreenshotHelperTest < ActiveSupport::TestCase - def test_driver_support_for_screenshots - Rails::SystemTestCase.driver = :rails_selenium_driver - assert Rails::SystemTestCase.driver.supports_screenshots? - - Rails::SystemTestCase.driver = :rack_test - assert_not Rails::SystemTestCase.driver.supports_screenshots? - - Rails::SystemTestCase.driver = :selenium - assert Rails::SystemTestCase.driver.supports_screenshots? - - Rails::SystemTestCase.driver = :webkit - assert Rails::SystemTestCase.driver.supports_screenshots? - - Rails::SystemTestCase.driver = :poltergeist - assert Rails::SystemTestCase.driver.supports_screenshots? - end -end -- cgit v1.2.3 From 1a0ca84a064b07ecab798793a3d7ebe89bb6367c Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 19 Feb 2017 11:50:42 -0500 Subject: Move and rename system tests * Move system tests back into Action Pack * Rename `ActionSystemTest` to `ActionDispatch::SystemTestCase` * Remove private base module and only make file for public `SystemTestCase` class, name private module `SystemTesting` * Rename `ActionSystemTestCase` to `ApplicationSystemTestCase` * Update corresponding documentation and guides * Delete old `ActionSystemTest` files --- .../test/dispatch/system_testing/browser_test.rb | 10 ++++++++++ .../test/dispatch/system_testing/driver_test.rb | 9 +++++++++ .../system_testing/screenshot_helper_test.rb | 10 ++++++++++ .../test/dispatch/system_testing/server_test.rb | 10 ++++++++++ .../system_testing/system_test_case_test.rb | 21 +++++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 actionpack/test/dispatch/system_testing/browser_test.rb create mode 100644 actionpack/test/dispatch/system_testing/driver_test.rb create mode 100644 actionpack/test/dispatch/system_testing/screenshot_helper_test.rb create mode 100644 actionpack/test/dispatch/system_testing/server_test.rb create mode 100644 actionpack/test/dispatch/system_testing/system_test_case_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/system_testing/browser_test.rb b/actionpack/test/dispatch/system_testing/browser_test.rb new file mode 100644 index 0000000000..b0ad309492 --- /dev/null +++ b/actionpack/test/dispatch/system_testing/browser_test.rb @@ -0,0 +1,10 @@ +require "abstract_unit" +require "action_dispatch/system_testing/browser" + +class BrowserTest < ActiveSupport::TestCase + test "initializing the browser" do + browser = ActionDispatch::SystemTesting::Browser.new(:chrome, [ 1400, 1400 ]) + assert_equal :chrome, browser.instance_variable_get(:@name) + assert_equal [ 1400, 1400 ], browser.instance_variable_get(:@screen_size) + end +end diff --git a/actionpack/test/dispatch/system_testing/driver_test.rb b/actionpack/test/dispatch/system_testing/driver_test.rb new file mode 100644 index 0000000000..f0ebdb38db --- /dev/null +++ b/actionpack/test/dispatch/system_testing/driver_test.rb @@ -0,0 +1,9 @@ +require "abstract_unit" +require "action_dispatch/system_testing/driver" + +class DriverTest < ActiveSupport::TestCase + test "initializing the driver" do + driver = ActionDispatch::SystemTesting::Driver.new(:selenium) + assert_equal :selenium, driver.instance_variable_get(:@name) + end +end diff --git a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb new file mode 100644 index 0000000000..3da89f4a10 --- /dev/null +++ b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb @@ -0,0 +1,10 @@ +require "abstract_unit" +require "action_dispatch/system_testing/test_helpers/screenshot_helper" + +class ScreenshotHelperTest < ActiveSupport::TestCase + test "image path is saved in tmp directory" do + new_test = ActionDispatch::SystemTestCase.new("x") + + assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path) + end +end diff --git a/actionpack/test/dispatch/system_testing/server_test.rb b/actionpack/test/dispatch/system_testing/server_test.rb new file mode 100644 index 0000000000..66842f4ea9 --- /dev/null +++ b/actionpack/test/dispatch/system_testing/server_test.rb @@ -0,0 +1,10 @@ +require "abstract_unit" +require "capybara/dsl" +require "action_dispatch/system_testing/server" + +class ServerTest < ActiveSupport::TestCase + test "initializing the server port" do + server = ActionDispatch::SystemTesting::Server.new.run + assert_includes Capybara.servers, :rails_puma + end +end diff --git a/actionpack/test/dispatch/system_testing/system_test_case_test.rb b/actionpack/test/dispatch/system_testing/system_test_case_test.rb new file mode 100644 index 0000000000..a384902a14 --- /dev/null +++ b/actionpack/test/dispatch/system_testing/system_test_case_test.rb @@ -0,0 +1,21 @@ +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 + end + + test "driven_by sets Capybara's drivers respectively" do + ActionDispatch::SystemTestCase.driven_by :selenium, using: :chrome + + assert_includes Capybara.drivers, :selenium + assert_includes Capybara.drivers, :chrome + assert_equal :chrome, Capybara.default_driver + end + + test "selenium? returns false if driver is poltergeist" do + assert_not ActionDispatch::SystemTestCase.selenium?(:poltergeist) + end +end -- cgit v1.2.3 From 983275eb7c01eaeba5798a422514f4d9d6b74786 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 19 Feb 2017 12:12:06 -0500 Subject: Fix screenshot helper to provide correct file name We only want the file name to include the word `failures` if it failed, not any time the user wants to take a screenshot during a test run. --- .../test/dispatch/system_testing/screenshot_helper_test.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb index 3da89f4a10..8c14f799b0 100644 --- a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb +++ b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb @@ -5,6 +5,14 @@ class ScreenshotHelperTest < ActiveSupport::TestCase test "image path is saved in tmp directory" do new_test = ActionDispatch::SystemTestCase.new("x") - assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path) + assert_equal "tmp/screenshots/x.png", new_test.send(:image_path) + end + + test "image path includes failures text if test did not pass" do + new_test = ActionDispatch::SystemTestCase.new("x") + + new_test.stub :passed?, false do + assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path) + end end end -- cgit v1.2.3 From 161cf89e134267f9b579f493ca19b12c30d5fd36 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 19 Feb 2017 17:49:21 -0500 Subject: Fix default host in setup, move teardown to helper file * Override integration test default host Integration tests automatically set the default host to 'http://example.com'. This works fine for integration tests because they are not real browser sessions, but doesn't work fine for system tests because they are real browser sessions. We can override this by setting the `host!` in `before_setup. The `Capybara.always_include_port` will allow the test to look at `127.0.0.1:port capybara picks` and properly redirect the test. Any application can override this by setting the `host!` in their system test helper. Generally though, applications are going to be using localhost. In this commit I also moved the setup and teardown into their own module for tidiness. * Move teardown settings into system test case These configuration options can be put into the system test case file instead of the generated system tests helper file. This is an implementation detail and therefore shouldn't be generated with the template. --- actionpack/test/dispatch/system_testing/server_test.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/system_testing/server_test.rb b/actionpack/test/dispatch/system_testing/server_test.rb index 66842f4ea9..10412d6367 100644 --- a/actionpack/test/dispatch/system_testing/server_test.rb +++ b/actionpack/test/dispatch/system_testing/server_test.rb @@ -3,8 +3,15 @@ require "capybara/dsl" require "action_dispatch/system_testing/server" class ServerTest < ActiveSupport::TestCase + setup do + ActionDispatch::SystemTesting::Server.new.run + end + test "initializing the server port" do - server = ActionDispatch::SystemTesting::Server.new.run assert_includes Capybara.servers, :rails_puma end + + test "port is always included" do + assert Capybara.always_include_port, "expected Capybara.always_include_port to be true" + end end -- cgit v1.2.3