Module: Rspec::Flaky::Test

Defined in:
lib/rspec/flaky/test.rb,
lib/rspec/flaky/test/version.rb

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.apply!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rspec/flaky/test.rb', line 6

def self.apply!
  RSpec.configure do |config|
    config.add_setting :flaky_tries, default: 3

    config.around(:example) do |example|
      next example.run unless example.[:flaky]

      tries = RSpec.configuration.flaky_tries
      current_example = RSpec.current_example

      tries.times do |try_count|
        # Clear the exception before we retry.
        current_example.instance_variable_set(:@exception, nil)

        example.run

        break unless current_example.exception
      end
    end
  end
end