1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Gracefully handle infinite redirects

Under rack-test at least. Generalizing this to
all drivers failed miserably.
This commit is contained in:
Jonas Nicklas 2010-01-11 21:30:58 +01:00
parent 159424151b
commit a34178859b
2 changed files with 13 additions and 2 deletions

View file

@ -9,6 +9,7 @@ module Capybara
class ElementNotFound < CapybaraError; end
class NotSupportedByDriverError < CapybaraError; end
class TimeoutError < CapybaraError; end
class InfiniteRedirectError < TimeoutError; end
class << self
attr_accessor :debug, :asset_root, :app_host

View file

@ -144,7 +144,7 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
def visit(path, attributes = {})
get(path, attributes)
follow_redirect! while response.redirect?
follow_redirects!
cache_body
end
@ -158,7 +158,7 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
def submit(path, attributes)
post(path, attributes)
follow_redirect! while response.redirect?
follow_redirects!
cache_body
end
@ -167,6 +167,16 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
end
private
def follow_redirects!
Capybara::WaitUntil.timeout(4) do
redirect = response.redirect?
follow_redirect! if redirect
not redirect
end
rescue Capybara::TimeoutError
raise Capybara::InfiniteRedirectError, "infinite redirect detected!"
end
def cache_body
@body = response.body