Fix paths relative to root path in rack-test, closes #454

This commit is contained in:
Jonas Nicklas and Nicklas Ramhöj 2011-08-30 10:54:20 +02:00
parent f4002f612a
commit 39eac9af37
4 changed files with 12 additions and 6 deletions

View File

@ -43,11 +43,10 @@ class Capybara::RackTest::Browser
end
if new_uri.relative?
path = request_path + path if path.start_with?('?')
unless path.start_with?('/')
folders = request_path.split('/')
path = (folders[0, folders.size - 1] << path).join('/')
if path.start_with?('?')
path = request_path + path
elsif not path.start_with?('/')
path = request_path.sub(%r(/[^/]*$), '/') + path
end
path = current_host + path
end

View File

@ -70,6 +70,12 @@ shared_examples_for "click_link" do
end
end
it "should follow relative links" do
@session.visit('/')
@session.click_link('Relative')
@session.body.should include('This is a test')
end
it "should follow redirects" do
@session.click_link('Redirect')
@session.body.should include('You landed')

View File

@ -7,7 +7,7 @@ class TestApp < Sinatra::Base
set :static, true
get '/' do
'Hello world!'
'Hello world! <a href="with_html">Relative</a>'
end
get '/foo' do

View File

@ -39,6 +39,7 @@
<a href="#anchor">Anchor</a>
<a href="/with_simple_html#anchor">Anchor on different page</a>
<a href="/with_html#anchor">Anchor on same page</a>
<a href="with_html">Relative</a>
<input type="text" value="" id="test_field">
<input type="text" checked="checked" id="checked_field">
<a href="/redirect"><img width="20" height="20" alt="very fine image" /></a>