Class: Minitest::Reporters::FailedTestsReporter
- Inherits:
-
BaseReporter
- Object
- BaseReporter
- Minitest::Reporters::FailedTestsReporter
- 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: `bundle exec rails test $(cat .minitest_failed_tests.txt)`
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ FailedTestsReporter
constructor
A new instance of FailedTestsReporter.
- #record(test) ⇒ Object
- #report ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ FailedTestsReporter
Returns a new instance of FailedTestsReporter.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/minitest_rerun_failed/failed_tests_reporter.rb', line 18 def initialize( = {}) super() @options = # Include line numbers? (failed_test.rb:42 or just failed_test.rb) @include_line_numbers = .fetch(:include_line_numbers, true) # Output to console? @verbose = .fetch(:verbose, true) # Output to file? @file_output = .fetch(:file_output, true) # What path to file? @output_path = .fetch(:output_path, ".") FileUtils.mkdir_p(@output_path) if @output_path @output_file_path = File.join(@output_path, ".minitest_failed_tests.txt") end |
Instance Method Details
#record(test) ⇒ Object
35 36 37 |
# File 'lib/minitest_rerun_failed/failed_tests_reporter.rb', line 35 def record(test) tests << test end |
#report ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/minitest_rerun_failed/failed_tests_reporter.rb', line 39 def report super failure_paths = [] file_output = [] curdir = FileUtils.pwd tests.each do |test| next if test.skipped? next if test.failure.nil? # DEBUG OUTPUT STR # p '=============================================' # p "Failure:\n#{test.class}##{test.name} [#{test.failure.location}]\n#{test.failure.class}: #{test.failure.message}" # p '=============================================' failure_file_location = find_failure_location(test, curdir) failure_paths << failure_file_location if failure_file_location end output_results(failure_paths, file_output) File.write(@output_file_path, file_output.join("\n"), encoding: "UTF-8") end |