Class: Minitest::Utils::Reporter

Inherits:
StatisticsReporter
  • Object
show all
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

Constructor Details

#initializeReporter

Returns a new instance of Reporter.



25
26
27
28
# File 'lib/minitest/utils/reporter.rb', line 25

def initialize(*)
  super
  @color_enabled = io.respond_to?(:tty?) && io.tty?
end

Class Method Details

.filtersObject



6
7
8
# File 'lib/minitest/utils/reporter.rb', line 6

def self.filters
  @filters ||= [/'Benchmark.measure'/]
end

Instance Method Details

#record(result) ⇒ Object



30
31
32
33
# File 'lib/minitest/utils/reporter.rb', line 30

def record(result)
  super
  print_result_code(result.result_code)
end

#reportObject



43
44
45
46
47
48
49
50
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/minitest/utils/reporter.rb', line 43

def report
  super
  io.sync = true

  failing_results = results.reject(&:skipped?)
  skipped_results = results.select(&:skipped?)

  color = :green
  color = :yellow if skipped_results.any?
  color = :red if failing_results.any?

  if failing_results.any? || skipped_results.any?
    failing_results.each.with_index(1) do |result, index|
      display_failing(result, index)
    end

    skipped_results
      .each
      .with_index(failing_results.size + 1) do |result, index|
      display_skipped(result, index)
    end
  end

  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
    threshold = 0.1 # 100ms
    test_results =
      Test
      .tests
      .values
      .select { _1[:benchmark] }
      .sort_by { _1[:benchmark].total }
      .reverse
      .take(10).filter { _1[:benchmark].total > threshold }

    return unless test_results.any?

    io.puts "\nSlow Tests:\n"

    test_results.each_with_index do |info, index|
      location = info[:source_location].join(":")
      duration = humanize_duration(info[:benchmark].total * 1_000_000_000)

      prefix = "#{index + 1}) "
      padding = " " * prefix.size

      io.puts color("#{prefix}#{info[:description]} (#{duration})", :red)
      io.puts color("#{padding}#{location}", :gray)
      io.puts
    end
  end
end

#startObject



35
36
37
38
39
40
41
# File 'lib/minitest/utils/reporter.rb', line 35

def start
  super
  io.puts "Run options: #{options[:args]}"
  io.puts
  io.puts "# Running:"
  io.puts
end