Class: TurboTests::Flaky::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_tests/flaky/manager.rb

Constant Summary collapse

PATH =
Rails.root.join("tmp/turbo_rspec_flaky_tests.json")

Class Method Summary collapse

Class Method Details

.log_potential_flaky_tests(failed_examples) ⇒ Object

This method should only be called by a formatter registered with ‘TurboTests::Runner` and logs the failed examples to `PATH`. See `FailedExample#to_h` for the details of each example that is logged.

Parameters:



22
23
24
25
26
27
28
29
30
# File 'lib/turbo_tests/flaky/manager.rb', line 22

def self.log_potential_flaky_tests(failed_examples)
  return if failed_examples.empty?

  File.open(PATH, "w") do |file|
    file.puts(
      failed_examples.map { |failed_example| FailedExample.new(failed_example).to_h }.to_json,
    )
  end
end

.potential_flaky_testsObject



8
9
10
11
12
# File 'lib/turbo_tests/flaky/manager.rb', line 8

def self.potential_flaky_tests
  JSON
    .parse(File.read(PATH))
    .map { |failed_example| failed_example["location_rerun_argument"] }
end

.remove_example(failed_examples) ⇒ Object

This method should only be called by a formatter registered with ‘RSpec::Core::Formatters.register` and removes the given examples from the log file at `PATH` by matching the `location_rerun_argument` of each example.

Parameters:

  • failed_examples (Array<RSpec::Core::Example>)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/turbo_tests/flaky/manager.rb', line 36

def self.remove_example(failed_examples)
  flaky_tests =
    JSON
      .parse(File.read(PATH))
      .reject do |failed_example|
        failed_examples.any? do |example|
          failed_example["location_rerun_argument"] == example.location_rerun_argument
        end
      end

  if flaky_tests.present?
    File.write(PATH, flaky_tests.to_json)
  else
    File.delete(PATH)
  end
end

.remove_flaky_testsObject



14
15
16
# File 'lib/turbo_tests/flaky/manager.rb', line 14

def self.remove_flaky_tests
  File.delete(PATH) if File.exist?(PATH)
end