diff options
7 files changed, 39 insertions, 16 deletions
diff --git a/actionpack/lib/action_dispatch/system_test_case.rb b/actionpack/lib/action_dispatch/system_test_case.rb index 850f101ca8..91cbc1180c 100644 --- a/actionpack/lib/action_dispatch/system_test_case.rb +++ b/actionpack/lib/action_dispatch/system_test_case.rb @@ -4,6 +4,7 @@ require "action_dispatch/system_testing/driver" require "action_dispatch/system_testing/server" require "action_dispatch/system_testing/browser" require "action_dispatch/system_testing/test_helpers/screenshot_helper" +require "action_dispatch/system_testing/test_helpers/setup_and_teardown" module ActionDispatch class SystemTestCase < IntegrationTest @@ -92,6 +93,7 @@ module ActionDispatch # and Rails, any driver that is supported by Capybara is supported by system # tests as long as you include the required gems and files. include Capybara::DSL + include SystemTesting::TestHelpers::SetupAndTeardown include SystemTesting::TestHelpers::ScreenshotHelper def self.start_application # :nodoc: diff --git a/actionpack/lib/action_dispatch/system_testing/server.rb b/actionpack/lib/action_dispatch/system_testing/server.rb index 62ba07736b..4a214ef713 100644 --- a/actionpack/lib/action_dispatch/system_testing/server.rb +++ b/actionpack/lib/action_dispatch/system_testing/server.rb @@ -16,8 +16,17 @@ module ActionDispatch end def setup + set_server + set_port + end + + def set_server Capybara.server = :rails_puma end + + def set_port + Capybara.always_include_port = true + end end end end diff --git a/actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb b/actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb new file mode 100644 index 0000000000..491559eedf --- /dev/null +++ b/actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb @@ -0,0 +1,20 @@ +module ActionDispatch + module SystemTesting + module TestHelpers + module SetupAndTeardown # :nodoc: + DEFAULT_HOST = "127.0.0.1" + + def before_setup + host! DEFAULT_HOST + super + end + + def after_teardown + super + take_failed_screenshot + Capybara.reset_sessions! + end + end + end + end +end 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 diff --git a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb index 440689b503..d19212abd5 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/system_test_helper.rb @@ -2,9 +2,4 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] - - teardown do - take_failed_screenshot - Capybara.reset_sessions! - end end diff --git a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb index 440689b503..d19212abd5 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb +++ b/railties/lib/rails/generators/rails/plugin/templates/test/system_test_helper.rb @@ -2,9 +2,4 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] - - teardown do - take_failed_screenshot - Capybara.reset_sessions! - end end diff --git a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb index 440689b503..d19212abd5 100644 --- a/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb +++ b/railties/lib/rails/generators/test_unit/system/templates/system_test_helper.rb @@ -2,9 +2,4 @@ require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] - - teardown do - take_failed_screenshot - Capybara.reset_sessions! - end end |