mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Detect infinite redirection (i.e. more than 5 redirects).
This originally worked with a timeout. Jonas fixed it so that it follows 5 redirects, but the infinite redirect error was not raised.
This commit is contained in:
parent
87abb6cf0f
commit
5b72525a96
4 changed files with 28 additions and 3 deletions
|
@ -256,8 +256,10 @@ private
|
|||
5.times do
|
||||
follow_redirect! if response.redirect?
|
||||
end
|
||||
rescue Capybara::TimeoutError
|
||||
raise Capybara::InfiniteRedirectError, "infinite redirect detected!"
|
||||
|
||||
if response.redirect?
|
||||
raise Capybara::InfiniteRedirectError, "infinite redirect detected!"
|
||||
end
|
||||
end
|
||||
|
||||
def env
|
||||
|
|
|
@ -193,4 +193,17 @@ shared_examples_for "driver with cookies support" do
|
|||
@driver.body.should_not include('test_cookie')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for "driver with infinite redirect detection" do
|
||||
it "should follow 5 redirects" do
|
||||
@driver.visit('/redirect/5/times')
|
||||
@driver.body.should include('redirection complete')
|
||||
end
|
||||
|
||||
it "should not follow more than 5 redirects" do
|
||||
running do
|
||||
@driver.visit('/redirect/6/times')
|
||||
end.should raise_error(Capybara::InfiniteRedirectError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,6 +22,15 @@ class TestApp < Sinatra::Base
|
|||
redirect '/landed'
|
||||
end
|
||||
|
||||
get '/redirect/:times/times' do
|
||||
times = params[:times].to_i
|
||||
if times.zero?
|
||||
"redirection complete"
|
||||
else
|
||||
redirect "/redirect/#{times - 1}/times"
|
||||
end
|
||||
end
|
||||
|
||||
get '/landed' do
|
||||
"You landed"
|
||||
end
|
||||
|
|
|
@ -15,4 +15,5 @@ describe Capybara::Driver::RackTest do
|
|||
it_should_behave_like "driver with header support"
|
||||
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"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue