From 4c94d3e0a09151a84c5bc1eb044b082e2b07993f Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Sun, 2 Apr 2017 19:06:58 +0900 Subject: Set `Capybara.app_host` through `host!` `visit "/"` will visit always "http://127.0.0.1" even when we call `host!`: ```ruby class SomeTest < ApplicationSystemTest def setup host! "http://example.com" end def test_visit visit root_url # => visit "http://example.com/" visit "/" # => visit "http://127.0.0.1/" end end ``` Because Capybara assumes that host is same as the server if we don't set `Capybara.app_host`: https://github.com/teamcapybara/capybara/blob/866c975076f92b5d064ee8998be638dd213f0724/lib/capybara/session.rb#L239 --- .../system_testing/test_helpers/setup_and_teardown.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch') 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 187ba2cc5f..f03f0d4299 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 @@ -2,7 +2,12 @@ module ActionDispatch module SystemTesting module TestHelpers module SetupAndTeardown # :nodoc: - DEFAULT_HOST = "127.0.0.1" + DEFAULT_HOST = "http://127.0.0.1" + + def host!(host) + super + Capybara.app_host = host + end def before_setup host! DEFAULT_HOST -- cgit v1.2.3