mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Don't override port if it's explicitly specified
This commit is contained in:
parent
e283c1aeaa
commit
e14c15fcef
2 changed files with 25 additions and 5 deletions
|
@ -247,15 +247,16 @@ module Capybara
|
|||
raise_server_error!
|
||||
@touched = true
|
||||
|
||||
visit_uri = URI.parse(visit_uri.to_s)
|
||||
visit_uri = ::Addressable::URI.parse(visit_uri.to_s)
|
||||
|
||||
uri_base = if @server
|
||||
visit_uri.port = @server.port if config.always_include_port && (visit_uri.port == visit_uri.default_port)
|
||||
URI.parse(config.app_host || "http://#{@server.host}:#{@server.port}")
|
||||
::Addressable::URI.parse(config.app_host || "http://#{@server.host}:#{@server.port}")
|
||||
else
|
||||
config.app_host && URI.parse(config.app_host)
|
||||
config.app_host && ::Addressable::URI.parse(config.app_host)
|
||||
end
|
||||
|
||||
uri_base.port ||= @server.port if @server && config.always_include_port
|
||||
|
||||
# TODO - this is only for compatability with previous 2.x behavior that concatenated
|
||||
# Capybara.app_host and a "relative" path - Consider removing in 3.0
|
||||
# @abotalov brought up a good point about this behavior potentially being useful to people
|
||||
|
@ -264,7 +265,9 @@ module Capybara
|
|||
visit_uri.path = uri_base.path + visit_uri.path
|
||||
end
|
||||
|
||||
visit_uri = uri_base.merge(visit_uri) unless uri_base.nil?
|
||||
if uri_base && [nil, 'http', 'https'].include?(visit_uri.scheme)
|
||||
visit_uri = uri_base.merge(visit_uri.to_hash.delete_if { |k,v| v.nil? })
|
||||
end
|
||||
|
||||
driver.visit(visit_uri.to_s)
|
||||
end
|
||||
|
|
|
@ -63,6 +63,23 @@ Capybara::SpecHelper.spec '#visit' do
|
|||
expect(URI.parse(@session.current_url).port).to eq(root_uri.port)
|
||||
expect(@session).to have_content('Another World')
|
||||
end
|
||||
|
||||
it "should add the server port to a visited url if no port specified", requires: [:server] do
|
||||
expect(@session.driver).to receive(:visit).with("http://www.example.com:#{@session.server.port}")
|
||||
@session.visit("http://www.example.com")
|
||||
end
|
||||
|
||||
it "should not override the visit specified port even if default for scheme", requires: [:server] do
|
||||
expect(@session.driver).to receive(:visit).with("http://www.example.com:80")
|
||||
@session.visit('http://www.example.com:80')
|
||||
end
|
||||
|
||||
it "should give preference to app_host port if specified", requires: [:server] do
|
||||
Capybara.app_host = "http://www.example.com:6666"
|
||||
expect(@session.driver).to receive(:visit).with("http://www.example.com:6666/random")
|
||||
@session.visit('/random')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "without a server", requires: [:server] do
|
||||
|
|
Loading…
Reference in a new issue