class Minitest::SummarizeReporter

Define our custom reporter.

Constants

CODE_TO_COLOR
COLOR_CODE
STATS_FORMAT
SUMMARY_LABELS

Public Class Methods

color!() click to toggle source
# File lib/minitest/summarize_reporter.rb, line 28
def self.color!
  @color = true
end
color?() click to toggle source
# File lib/minitest/summarize_reporter.rb, line 36
def self.color?
  @color
end
new(io) click to toggle source
Calls superclass method
# 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
no_color!() click to toggle source
# File lib/minitest/summarize_reporter.rb, line 32
def self.no_color!
  @color = false
end

Public Instance Methods

aggregated_results() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
Calls superclass method
# 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() click to toggle source
Calls superclass method
# 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() click to toggle source
# File lib/minitest/summarize_reporter.rb, line 72
def statistics
  format(STATS_FORMAT,
         total_time, count / total_time,
         assertions / total_time)
end
summarize_clear() click to toggle source
# File lib/minitest/summarize_reporter.rb, line 120
def summarize_clear
  @io.print ' ' * @last_length if @last_length
  @io.print "\r"
  @io.flush
end