Module: IntegrationTestsRails::Capybara::Dsl

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

Overview

This module provides the main DSL for writing integration tests with Capybara.

Instance Method Summary collapse

Instance Method Details

#retry_on_fail(attempts: nil, sleep_duration: nil, capture_exceptions: nil) ⇒ Object



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

def retry_on_fail(attempts: nil, sleep_duration: nil, capture_exceptions: nil)
  config = IntegrationTestsRails.configuration
  attempts ||= config.retry_attempts
  sleep_duration ||= config.retry_sleep_duration
  capture_exceptions ||= constantize_exceptions(config)
  counter = 0

  begin
    yield
  rescue *capture_exceptions => e
    counter += 1
    Util.log("Inline Retry Attempt #{counter} for #{RSpec.current_example.full_description} failed!")
    raise e if counter > attempts

    sleep(sleep_duration) if sleep_duration.positive?
    retry
  end
end