diff options
Diffstat (limited to 'spec/support/capybara_helpers.rb')
-rw-r--r-- | spec/support/capybara_helpers.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/support/capybara_helpers.rb b/spec/support/capybara_helpers.rb index 9b5c3065eed..a8ba786c130 100644 --- a/spec/support/capybara_helpers.rb +++ b/spec/support/capybara_helpers.rb @@ -29,6 +29,37 @@ module CapybaraHelpers end end +# See: https://github.com/teampoltergeist/poltergeist/issues/375#issuecomment-54171533 +def restart_phantomjs + puts "-> Restarting phantomjs: iterating through capybara sessions..." + session_pool = Capybara.send('session_pool') + session_pool.each do |mode,session| + msg = " => #{mode} -- " + driver = session.driver + if driver.is_a?(Capybara::Poltergeist::Driver) + msg += "restarting" + driver.restart + else + msg += "not poltergeist: #{driver.class}" + end + puts msg + end +end + +CAPYBARA_TIMEOUT_RETRIES = 3 + RSpec.configure do |config| config.include CapybaraHelpers, type: :feature + + config.around(:each, type: :feature) do |ex| + example = RSpec.current_example + CAPYBARA_TIMEOUT_RETRIES.times do |i| + example.instance_variable_set('@exception', nil) + self.instance_variable_set('@__memoized', nil) # clear let variables + ex.run + break unless example.exception.is_a?(Capybara::Poltergeist::TimeoutError) + puts("\nCapybara::Poltergeist::TimeoutError at #{example.location}\n Restarting phantomjs and retrying...") + restart_phantomjs + end + end end |