Class: Minitest::Reporters::TurnAgainReporter
- Inherits:
-
BaseReporter
- Object
- AbstractReporter
- Minitest::Reporter
- StatisticsReporter
- BaseReporter
- Minitest::Reporters::TurnAgainReporter
- Includes:
- ANSI::Code, RelativePosition
- Defined in:
- lib/minitest/reporters/turn_again_reporter.rb,
lib/minitest/reporters/turn_again_reporter/version.rb
Overview
Reporter whose output more closely mimics the format of the turn gem. Specifically:
- The status banner and time on the left, which removes the need to limit the length of test names to not risk mis-aligning status flags.
- Displays time as minutes:seconds, optionally with hours as well.
- Allows configuration of indentation for each test output. Turn uses 4 spaces, and thus this was chosen as the default.
Source is mostly a verbatim copy from minitest-reporter's SpecReporter class. Was unable to simply subclass SpecReporter without significant code gynmastics or metaprogramming unbecoming of a simple library formatter. This mostly due to SpecReporter's necessary calls to super within the #record method, mixed with unavoidable output.
Constant Summary collapse
- VERSION =
"1.1.0"
Instance Attribute Summary collapse
-
#error_color ⇒ Object
readonly
Returns the value of attribute error_color.
-
#fail_color ⇒ Object
readonly
Returns the value of attribute fail_color.
-
#hours ⇒ Object
readonly
Returns the value of attribute hours.
-
#indent ⇒ Object
readonly
Returns the value of attribute indent.
-
#pass_color ⇒ Object
readonly
Returns the value of attribute pass_color.
-
#skip_color ⇒ Object
readonly
Returns the value of attribute skip_color.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ TurnAgainReporter
constructor
A new instance of TurnAgainReporter.
-
#no_color(&block) ⇒ Object
To match the interface of printing of colors via methods with blocks.
- #option_defaults ⇒ Object
- #print_colored_status(test) ⇒ Object
-
#print_info(e, name = true) ⇒ Object
Divergence from Minitest::Reporters::SpecReporter is that here we are printing the exception name with padding, so that it doesn't break the visual flow/alignment of all the vertical, colored test result statuses.
- #record(test) ⇒ Object
- #report ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TurnAgainReporter
Returns a new instance of TurnAgainReporter.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 33 def initialize( = {}) = option_defaults.merge() @hours = !!.fetch(:hours) @indent = .fetch(:indent) @pass_color = .fetch(:pass_color) @fail_color = .fetch(:fail_color) @error_color = .fetch(:error_color) @skip_color = .fetch(:skip_color) super() end |
Instance Attribute Details
#error_color ⇒ Object (readonly)
Returns the value of attribute error_color.
30 31 32 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 30 def error_color @error_color end |
#fail_color ⇒ Object (readonly)
Returns the value of attribute fail_color.
30 31 32 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 30 def fail_color @fail_color end |
#hours ⇒ Object (readonly)
Returns the value of attribute hours.
30 31 32 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 30 def hours @hours end |
#indent ⇒ Object (readonly)
Returns the value of attribute indent.
30 31 32 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 30 def indent @indent end |
#pass_color ⇒ Object (readonly)
Returns the value of attribute pass_color.
30 31 32 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 30 def pass_color @pass_color end |
#skip_color ⇒ Object (readonly)
Returns the value of attribute skip_color.
30 31 32 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 30 def skip_color @skip_color end |
Instance Method Details
#no_color(&block) ⇒ Object
To match the interface of printing of colors via methods with blocks.
100 101 102 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 100 def no_color(&block) block.call end |
#option_defaults ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 45 def option_defaults { hours: false, indent: 4, pass_color: :green, fail_color: :red, error_color: :yellow, skip_color: :cyan, } end |
#print_colored_status(test) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 85 def print_colored_status(test) print_status = -> { pad_mark( result(test).to_s.upcase ) } if test.passed? print(send(pass_color, &print_status)) elsif test.skipped? print(send(skip_color, &print_status)) elsif test.error? print(send(error_color, &print_status)) else print(send(fail_color, &print_status)) end end |
#print_info(e, name = true) ⇒ Object
Divergence from Minitest::Reporters::SpecReporter is that here we are printing the exception name with padding, so that it doesn't break the visual flow/alignment of all the vertical, colored test result statuses.
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 122 def print_info(e, name=true) print_with_info_padding("#{e.exception.class.to_s}: ") if name e..each_line { |line| print_with_info_padding(line) } # When e is a Minitest::UnexpectedError, the filtered backtrace is already part of the message printed out # by the previous line. In that case, and that case only, skip the backtrace output. unless e.is_a?(MiniTest::UnexpectedError) trace = filter_backtrace(e.backtrace) trace.each { |line| print_with_info_padding(line) } end end |
#record(test) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 105 def record(test) super print (' ' * indent) print_colored_status(test) print format_time(test.time) print test.name puts if !test.skipped? && test.failure print_info(test.failure) puts end end |
#report ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 63 def report super passed = count - (failures + errors + skips) puts('Finished in %.5fs' % total_time) puts print(bold { '%d tests' } % count) print(', ') print(send(report_passed_color) { '%d passed' } % passed) print(', ') print(send(report_failures_color) { '%d failures' } % failures) print(', ') print(send(report_errors_color) { '%d errors' } % errors) print(', ') print(send(report_skips_color) { '%d skips' } % skips) print(', ') print('%d assertions' % assertions) puts end |
#start ⇒ Object
56 57 58 59 60 |
# File 'lib/minitest/reporters/turn_again_reporter.rb', line 56 def start super puts('Started with run options %s' % [:args]) puts end |