File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed
test/dispatch/system_testing
railties/test/application Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,8 @@ class SystemTestCase < ActiveSupport::TestCase
115
115
include SystemTesting ::TestHelpers ::SetupAndTeardown
116
116
include SystemTesting ::TestHelpers ::ScreenshotHelper
117
117
118
+ DEFAULT_HOST = "http://127.0.0.1"
119
+
118
120
def initialize ( *) # :nodoc:
119
121
super
120
122
self . class . driven_by ( :selenium ) unless self . class . driver?
@@ -166,7 +168,11 @@ def url_helpers
166
168
include ActionDispatch . test_app . routes . mounted_helpers
167
169
168
170
def url_options
169
- default_url_options . reverse_merge ( host : Capybara . app_host || Capybara . current_session . server_url )
171
+ default_url_options . reverse_merge ( host : app_host )
172
+ end
173
+
174
+ def app_host
175
+ Capybara . app_host || Capybara . current_session . server_url || DEFAULT_HOST
170
176
end
171
177
end . new
172
178
end
Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ class SetDriverToSeleniumHeadlessFirefoxTest < DrivenBySeleniumWithHeadlessFiref
36
36
end
37
37
38
38
class SetHostTest < DrivenByRackTest
39
+ teardown do
40
+ Capybara . app_host = nil
41
+ end
42
+
39
43
test "overrides host" do
40
44
assert_deprecated do
41
45
host! "http://example.com"
Original file line number Diff line number Diff line change @@ -26,7 +26,22 @@ def teardown
26
26
assert_not_includes ( ActionDispatch ::SystemTestCase . runnable_methods , :test_foo_url )
27
27
end
28
28
29
- test "system tests set the Capybara host in the url_options by default" do
29
+ test "system tests use 127.0.0.1 in the url_options be default" do
30
+ app_file "config/routes.rb" , <<-RUBY
31
+ Rails.application.routes.draw do
32
+ get 'foo', to: 'foo#index', as: 'test_foo'
33
+ end
34
+ RUBY
35
+
36
+ app ( "test" )
37
+ rack_test_case = Class . new ( ActionDispatch ::SystemTestCase ) do
38
+ driven_by :rack_test
39
+ end
40
+ system_test = rack_test_case . new ( "my_test" )
41
+ assert_equal ( "http://127.0.0.1/foo" , system_test . test_foo_url )
42
+ end
43
+
44
+ test "system tests use Capybara.app_host in the url_options if present" do
30
45
app_file "config/routes.rb" , <<-RUBY
31
46
Rails.application.routes.draw do
32
47
get 'foo', to: 'foo#index', as: 'test_foo'
You can’t perform that action at this time.
0 commit comments