Class: Minitest::Reporters::FailedTestsReporter

Inherits:
BaseReporter
  • Object
show all
Defined in:
lib/minitest_rerun_failed/failed_tests_reporter.rb

Overview

Source: www.houen.net/2021/08/23/minitest-rerun-failed-tests/ License: MIT

Outputs failed tests to screen and / or file Allows to rerun only failed tests with minitest if added to Minitest::Reporters.use!

Example:

In test_helper.rb or similar:
Minitest::Reporters.use! [
  Minitest::Reporters::ProgressReporter.new,
  Minitest::Reporters::FailedTestsReporter.new(verbose: true, include_line_numbers: true)
]

Now after a failed test run, rerun failed tests only with: `bin/rerun_failed_tests`

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FailedTestsReporter

Returns a new instance of FailedTestsReporter.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/minitest_rerun_failed/failed_tests_reporter.rb', line 21

def initialize(options = {})
  super
  @options = options

  # Include line numbers? (failed_test.rb:42 or just failed_test.rb)
  @include_line_numbers = options.fetch(:include_line_numbers, true)
  # Output to console?
  @verbose = options.fetch(:verbose, true)
  # Output to file?
  @file_output = options.fetch(:file_output, true)
  # What path to file?
  @output_path = options.fetch(:output_path, ".")
  FileUtils.mkdir_p(@output_path) if @file_output && @output_path

  @output_file_path = File.join(@output_path, ".minitest_failed_tests.txt")
end

Instance Method Details

#reportObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/minitest_rerun_failed/failed_tests_reporter.rb', line 38

def report
  super

  curdir = FileUtils.pwd
  failures = failed_results
  output_paths = failed_test_locations(failures, curdir).map(&:strip).uniq

  output_results(failures.count, output_paths)
  output_missing_locations(failures.count) if failures.any? && output_paths.empty?
  write_file_output(output_paths) if @file_output
end