Class: Minitest::SummarizeReporter
- Inherits:
-
StatisticsReporter
- Object
- StatisticsReporter
- Minitest::SummarizeReporter
- Defined in:
- lib/minitest/summarize_reporter.rb
Overview
Define our custom reporter.
Constant Summary collapse
- SUMMARY_LABELS =
{ '.' => 'Passed:', 'F' => 'Failed', 'E' => 'Error:', 'S' => 'Skipped:' }.freeze
- CODE_TO_COLOR =
{ '.' => :green, 'F' => :red, 'E' => :red, 'S' => :blue }.freeze
- COLOR_CODE =
{ red: 31, green: 32, blue: 34, none: 0 }.freeze
- STATS_FORMAT =
'Finished in %.6fs, %.4f runs/s, %.4f assertions/s.'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #aggregated_results ⇒ Object
- #colorize(code, str) ⇒ Object
- #colorize_by_key(key, str) ⇒ Object
- #format_string(key, label, value) ⇒ Object
- #generate_output ⇒ Object
-
#initialize(io) ⇒ SummarizeReporter
constructor
A new instance of SummarizeReporter.
- #record(result) ⇒ Object
- #report ⇒ Object
- #statistics ⇒ Object
- #summarize_clear ⇒ Object
Constructor Details
#initialize(io) ⇒ SummarizeReporter
Returns a new instance of SummarizeReporter.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/minitest/summarize_reporter.rb', line 40 def initialize(io) super io @io = io @summary = {} @last_length = 0 @color = true SUMMARY_LABELS.keys.each { |key| @summary[key] = 0 } end |
Class Method Details
.color! ⇒ Object
28 29 30 |
# File 'lib/minitest/summarize_reporter.rb', line 28 def self.color! @color = true end |
.color? ⇒ Boolean
36 37 38 |
# File 'lib/minitest/summarize_reporter.rb', line 36 def self.color? @color end |
.no_color! ⇒ Object
32 33 34 |
# File 'lib/minitest/summarize_reporter.rb', line 32 def self.no_color! @color = false end |
Instance Method Details
#aggregated_results ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/minitest/summarize_reporter.rb', line 78 def aggregated_results filtered_results = results.sort_by { |result| result.skipped? ? 1 : 0 } filtered_results.each_with_index.map do |result, idx| color = result.skipped? ? :yellow : :red text = format("\n%3d) %s", idx + 1, result) self.class.color? ? colorize(color, text) : text end.join + "\n" end |
#colorize(code, str) ⇒ Object
116 117 118 |
# File 'lib/minitest/summarize_reporter.rb', line 116 def colorize(code, str) "\e[#{COLOR_CODE[code]}m#{str}\e[0m" end |
#colorize_by_key(key, str) ⇒ Object
110 111 112 113 114 |
# File 'lib/minitest/summarize_reporter.rb', line 110 def colorize_by_key(key, str) code = CODE_TO_COLOR[key] colorize(code, str) end |
#format_string(key, label, value) ⇒ Object
104 105 106 107 108 |
# File 'lib/minitest/summarize_reporter.rb', line 104 def format_string(key, label, value) str = "#{label} #{value}" self.class.color? ? "[#{colorize_by_key(key, str)}]" : "[#{str}]" end |
#generate_output ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/minitest/summarize_reporter.rb', line 89 def generate_output list = [] SUMMARY_LABELS.each do |key, label| value = @summary[key] list.push format_string(key, label, value) end @last_format = list.join(' ') @last_length = @last_format.length @last_format + "\r" end |
#record(result) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/minitest/summarize_reporter.rb', line 51 def record(result) super code = result.result_code @summary[code] += 1 summarize_clear @io.print generate_output end |
#report ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/minitest/summarize_reporter.rb', line 63 def report super io.puts "\n\n" io.puts statistics io.puts aggregated_results io.puts "\n\n" end |
#statistics ⇒ Object
72 73 74 75 76 |
# File 'lib/minitest/summarize_reporter.rb', line 72 def statistics format(STATS_FORMAT, total_time, count / total_time, assertions / total_time) end |
#summarize_clear ⇒ Object
120 121 122 123 124 |
# File 'lib/minitest/summarize_reporter.rb', line 120 def summarize_clear @io.print ' ' * @last_length if @last_length @io.print "\r" @io.flush end |