Moved test to shared_example_for in driver, included test both for rack_test and selenium

This commit is contained in:
Rob van Dijk 2012-01-10 17:08:22 +01:00
parent bf1637eb6d
commit 757c135b8e
5 changed files with 14 additions and 15 deletions

View File

@ -126,5 +126,4 @@ protected
env
end
end

View File

@ -295,3 +295,11 @@ shared_examples_for "driver with infinite redirect detection" do
end.should raise_error(Capybara::InfiniteRedirectError)
end
end
shared_examples_for "driver with referer support" do
it "should preserve the original referer URL when following a redirect" do
@driver.visit('/referer_base')
@driver.find('//a[@href="redirect_and_keep_referer"]').first.click
@driver.body.should include('referer_base')
end
end

View File

@ -23,15 +23,15 @@ class TestApp < Sinatra::Base
end
get '/referer_base' do
'Referer base <a href="redirect_and_keep_referer">Link that will redirect</a>'
'Referer base: <a href="redirect_and_keep_referer">Link that will redirect</a>'
end
get '/redirect_and_keep_referer' do
redirect '/check_referer'
redirect '/get_referer'
end
get '/check_referer' do
'Check referer'
get '/get_referer' do
'Got referer: ' + request.referer
end
get '/host' do

View File

@ -30,6 +30,7 @@ describe Capybara::RackTest::Driver do
it_should_behave_like "driver with status code support"
it_should_behave_like "driver with cookies support"
it_should_behave_like "driver with infinite redirect detection"
it_should_behave_like "driver with referer support"
describe '#reset!' do
it { @driver.visit('/foo'); lambda { @driver.reset! }.should change(@driver, :current_url).to('') }
@ -86,14 +87,4 @@ describe Capybara::RackTest::Driver do
@driver.body.should include('foobar')
end
end
describe "keeping referer on redirect" do
it "should not update HTTP_REFERER on redirects" do
@driver.visit('/referer_base')
@driver.visit('/redirect_and_keep_referer')
@driver.body.should include('Check referer')
@driver.request.referer.should =~ /referer_base/
end
end
end

View File

@ -13,6 +13,7 @@ describe Capybara::Selenium::Driver do
it_should_behave_like "driver with support for window switching"
it_should_behave_like "driver without status code support"
it_should_behave_like "driver with cookies support"
it_should_behave_like "driver with referer support"
unless Config::CONFIG['host_os'] =~ /mswin|mingw/
it "should not interfere with forking child processes" do