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:
parent
159424151b
commit
a34178859b
2 changed files with 13 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue