Handle naked query string, closes #133

This commit is contained in:
Jonas Nicklas 2010-10-22 16:45:33 +02:00
parent 46134cc3f1
commit 3f688b0723
3 changed files with 18 additions and 7 deletions

View File

@ -185,6 +185,7 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
def process(method, path, attributes = {})
return if path.gsub(/^#{request_path}/, '') =~ /^#/
path = request_path + path if path =~ /^\?/
send(method, to_binary(path), to_binary( attributes ), env)
follow_redirects!
end

View File

@ -16,7 +16,7 @@ shared_examples_for "click_link" do
@session.click_link('labore')
@session.body.should include('Bar')
end
it "should accept partial matches" do
@session.click_link('abo')
@session.body.should include('Bar')
@ -38,7 +38,7 @@ shared_examples_for "click_link" do
@session.click_link('some tit')
@session.body.should include('Bar')
end
it "should prefer exact matches over partial matches" do
@session.click_link('a fine link')
@session.body.should include('Bar')
@ -74,12 +74,17 @@ shared_examples_for "click_link" do
@session.click_link('Redirect')
@session.body.should include('You landed')
end
it "should follow redirects" do
@session.click_link('BackToMyself')
@session.body.should include('This is a test')
end
it "should add query string to current URL with naked query string" do
@session.click_link('Naked Query String')
@session.body.should include('Query String sent')
end
it "should do nothing on anchor links" do
@session.fill_in("test_field", :with => 'blah')
@session.click_link('Anchor')
@ -87,18 +92,18 @@ shared_examples_for "click_link" do
@session.click_link('Blank Anchor')
@session.find_field("test_field").value.should == 'blah'
end
it "should do nothing on URL+anchor links for the same page" do
@session.fill_in("test_field", :with => 'blah')
@session.click_link('Anchor on same page')
@session.find_field("test_field").value.should == 'blah'
end
it "should follow link on URL+anchor links for a different page" do
@session.click_link('Anchor on different page')
@session.body.should include('Bar')
end
it "raise an error with links with no href" do
running do
@session.click_link('No Href')

View File

@ -35,6 +35,11 @@
<input type="text" checked="checked" id="checked_field">
<a href="/redirect"><img src="http://www.foobar.sun/dummy_image.jpg" width="20" height="20" alt="very fine image" /></a>
<a href="/with_simple_html"><img src="http://www.foobar.sun/dummy_image.jpg" width="20" height="20" alt="fine image" /></a>
<a href="?query_string=true">Naked Query String</a>
<% if params[:query_string] %>
<em>Query String sent</em>
<% end %>
</p>
<div id="hidden" style="display: none;">