Correctly handle moving to absolute URI without trailing slash, closes #1055

This commit is contained in:
Jonas Nicklas 2013-11-10 14:31:08 +01:00
parent 206ff438cb
commit 0f8eb34070
2 changed files with 14 additions and 4 deletions

View File

@ -46,6 +46,7 @@ class Capybara::RackTest::Browser
method.downcase! unless method.is_a? Symbol
new_uri.path = request_path if path.start_with?("?")
new_uri.path = "/" if new_uri.path.empty?
new_uri.path = request_path.sub(%r(/[^/]*$), '/') + new_uri.path unless new_uri.path.start_with?('/')
new_uri.scheme ||= @current_scheme
new_uri.host ||= @current_host
@ -93,11 +94,11 @@ class Capybara::RackTest::Browser
rescue Rack::Test::Error
""
end
def title
dom.xpath("//title").text
end
protected
def build_rack_mock_session

View File

@ -17,6 +17,15 @@ Capybara::SpecHelper.spec '#visit' do
@session.should have_content('Another World')
end
it "should fetch a response when absolute URI doesn't have a trailing slash" do
# Preparation
@session.visit('/foo/bar')
root_uri = URI.parse(@session.current_url)
@session.visit("http://localhost:#{root_uri.port}")
@session.should have_content('Hello world!')
end
context "when Capybara.always_include_port is true" do
let(:root_uri) do
@ -86,11 +95,11 @@ Capybara::SpecHelper.spec '#visit' do
@session.find('//input').click
@session.should have_content %r{http://.*/referer_base}
end
it "can set cookie if a blank path is specified" do
@session.visit("")
@session.visit('/get_cookie')
@session.should have_content('root cookie')
end
end