mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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`:
866c975076/lib/capybara/session.rb (L239)
This commit is contained in:
parent
19ae6597b8
commit
4c94d3e0a0
2 changed files with 18 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -19,3 +19,15 @@ class SetDriverToSeleniumTest < DrivenBySeleniumWithChrome
|
|||
assert_equal :selenium, Capybara.current_driver
|
||||
end
|
||||
end
|
||||
|
||||
class SetHostTest < DrivenByRackTest
|
||||
test "sets default host" do
|
||||
assert_equal "http://127.0.0.1", Capybara.app_host
|
||||
end
|
||||
|
||||
test "overrides host" do
|
||||
host! "http://example.com"
|
||||
|
||||
assert_equal "http://example.com", Capybara.app_host
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue