Module: ParallelTests::Retries

Included in:
Extensions
Defined in:
lib/parallel_tests/extensions.rb

Instance Method Summary collapse

Instance Method Details

#retry_failed_tests(ignore: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/parallel_tests/extensions.rb', line 8

def retry_failed_tests(ignore: nil)
  # Hacky
  if defined?(Minitest)
    if first_process?
      report = Minitest::Reporters::ParallelTestsReporter.compile_reports! 
      failed = report.select {|r| r[:failures].any?}
      if failed.any?
        puts "\nThe following tests failed:"
        puts failed.map {|f| f[:location]}.join("\n")

        puts "\nRe-running failed tests"
        # TODO Doesn't work, this is a backtrace for where the exception occurred, what if we fail on setup?
        found_all_test_files_for_failures = true
        test_failures = failed.flat_map do |test| 
          guessed_test_name = test[:test_class_name].split('::').last
          test_files = Dir["**/#{guessed_test_name.underscore}.rb"].entries
          found_all_test_files_for_failures = false if test_files.empty?
          test_files
        end

        test_files.reject! {|f| f[ignore]} if ignore

        # hack
        ENV.delete 'TEST_ENV_NUMBER'

        # TODO fix and variablize
        cmd = %Q{ruby -Ilib:test -e "#{test_failures.uniq.map {|f| "load '#{f}';"}.join("\n")}"}
        puts cmd
        did_pass = system cmd

        if did_pass && found_all_test_files_for_failures
          puts 'All tests passed on retry, marking build as success'
          exit(0)
        else
          # use default messaging
        end

        # TODO parse output and print status
      end
    end
  end
end