Module: IntegrationTestsRails::Capybara::Retry

Defined in:
lib/integration_tests_rails/capybara/retry.rb

Overview

Handles auto-retry logic for RSpec feature examples.

Class Method Summary collapse

Class Method Details

.run(example, context) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/integration_tests_rails/capybara/retry.rb', line 8

def run(example, context)
  description = example.full_description
  attempts, sleep_duration, capture_exceptions = retry_config(example)

  (attempts + 1).times do |attempt_number|
    reset_example_state(context)
    example.run
    ex = example.exception
    break unless ex
    break unless capture_exceptions.any? { |klass| ex.is_a?(klass) }

    Util.log "Auto Retry Attempt #{attempt_number + 1} failed for: #{description} (#{ex.class})"
    sleep(sleep_duration) if attempt_number < attempts && sleep_duration.positive?
  end
end