Class: Minitest::Utils::Reporter
- Inherits:
-
StatisticsReporter
- Object
- StatisticsReporter
- Minitest::Utils::Reporter
- Defined in:
- lib/minitest/utils/reporter.rb
Constant Summary collapse
- COLOR_FOR_RESULT_CODE =
{ "." => :green, "E" => :red, "F" => :red, "S" => :yellow }.freeze
- COLOR =
{ red: 31, green: 32, yellow: 33, blue: 34, gray: 37 }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #bundler ⇒ Object
- #format_duration(duration_in_seconds) ⇒ Object
-
#initialize ⇒ Reporter
constructor
A new instance of Reporter.
- #print_failing_results(results, initial_index = 1) ⇒ Object
- #print_skipped_results(results, initial_index) ⇒ Object
- #print_slow_results ⇒ Object
- #record(result) ⇒ Object
- #report ⇒ Object
- #slow_tests ⇒ Object
- #slow_threshold_for(test_case) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ Reporter
Returns a new instance of Reporter.
36 37 38 39 |
# File 'lib/minitest/utils/reporter.rb', line 36 def initialize(*) super @color_enabled = io.respond_to?(:tty?) && io.tty? end |
Class Method Details
.filters ⇒ Object
17 18 19 |
# File 'lib/minitest/utils/reporter.rb', line 17 def self.filters @filters ||= [] end |
Instance Method Details
#bundler ⇒ Object
293 294 295 |
# File 'lib/minitest/utils/reporter.rb', line 293 def bundler "bundle exec " if ENV.key?("BUNDLE_BIN_PATH") end |
#format_duration(duration_in_seconds) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/minitest/utils/reporter.rb', line 127 def format_duration(duration_in_seconds) duration_ns = duration_in_seconds * 1_000_000_000 number, unit = if duration_ns < 1000 [duration_ns, "ns"] elsif duration_ns < 1_000_000 [duration_ns / 1000, "μs"] elsif duration_ns < 1_000_000_000 [duration_ns / 1_000_000, "ms"] else [duration_ns / 1_000_000_000, "s"] end number = format("%.2f", number).gsub(/0+$/, "").delete_suffix(".") "#{number}#{unit}" end |
#print_failing_results(results, initial_index = 1) ⇒ Object
92 93 94 95 96 |
# File 'lib/minitest/utils/reporter.rb', line 92 def print_failing_results(results, initial_index = 1) results.each.with_index(initial_index) do |result, index| display_failing(result, index) end end |
#print_skipped_results(results, initial_index) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/minitest/utils/reporter.rb', line 98 def print_skipped_results(results, initial_index) results .each .with_index(initial_index + 1) do |result, index| display_skipped(result, index) end end |
#print_slow_results ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/minitest/utils/reporter.rb', line 106 def print_slow_results test_results = slow_tests.take(10) return if Minitest.[:hide_slow] return unless test_results.any? io.puts "\nSlow Tests:\n" test_results.each_with_index do |info, index| location = info[:source_location].join(":") duration = format_duration(info[:time]) prefix = "#{index + 1}) " padding = " " * prefix.size io.puts color("#{prefix}#{info[:description]} (#{duration})", :red) io.puts color("#{padding}#{location}", :blue) io.puts end end |
#record(result) ⇒ Object
46 47 48 49 |
# File 'lib/minitest/utils/reporter.rb', line 46 def record(result) super print_result_code(result.result_code) end |
#report ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/minitest/utils/reporter.rb', line 51 def report super io.sync = true if io.respond_to?(:sync) failing_results = results.reject(&:skipped?) skipped_results = results.select(&:skipped?) color = :green color = :yellow if skipped_results.any? color = :red if failing_results.any? print_failing_results(failing_results) print_skipped_results(skipped_results, failing_results.size) io.print "\n\n" io.puts statistics io.puts color(summary, color) if failing_results.any? io.puts "\nFailed Tests:\n" failing_results.each {|result| display_replay_command(result) } io.puts "\n\n" else print_slow_results end end |
#slow_tests ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/minitest/utils/reporter.rb', line 82 def slow_tests Test .tests .values .select { _1[:time] } .filter { _1[:time] > slow_threshold_for(_1) } .sort_by { _1[:time] } .reverse end |
#slow_threshold_for(test_case) ⇒ Object
78 79 80 |
# File 'lib/minitest/utils/reporter.rb', line 78 def slow_threshold_for(test_case) test_case[:slow_threshold] || Minitest.[:slow_threshold] || 0.1 end |
#start ⇒ Object
41 42 43 44 |
# File 'lib/minitest/utils/reporter.rb', line 41 def start super io.puts "Run options: #{[:args]}\n" end |