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. --- .../test_helpers/setup_and_teardown.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb (limited to 'actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb') 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 -- cgit v1.2.3 From 3da239a2cd43d04c5f972fa8f8e57e64a139194c Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 28 Feb 2017 09:59:02 +0900 Subject: Take failed screenshot before reset driver Now reset the driver before take failed screenshot since #28144. However, I think that failed screenshot should be take with the driver actually used in the test. So, fixed to take screenshot before reset driver. --- .../action_dispatch/system_testing/test_helpers/setup_and_teardown.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb') 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 index 491559eedf..1c89bfacfa 100644 --- 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 @@ -10,8 +10,8 @@ module ActionDispatch end def after_teardown - super take_failed_screenshot + super Capybara.reset_sessions! end end -- cgit v1.2.3 From 5edbdca5c0db00b0724bc0c9202c83194b688ae8 Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Wed, 1 Mar 2017 20:39:29 +0900 Subject: Fix random failure on system test with ajax If application has ajax, browser may begin request after rollback. `teardown_fixtures` will be called after `super` on `after_teardown` so we must call `Capybara.reset_sessions!` before `super` https://github.com/rails/rails/blob/b61a56541aecd7ac685d4f19d943177a3f1b465a/activerecord/lib/active_record/fixtures.rb#L857 --- .../action_dispatch/system_testing/test_helpers/setup_and_teardown.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb') 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 index 1c89bfacfa..187ba2cc5f 100644 --- 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 @@ -11,8 +11,8 @@ module ActionDispatch def after_teardown take_failed_screenshot - super Capybara.reset_sessions! + super end end end -- cgit v1.2.3