Class: Minitest::Reporters::DefaultReporter

Inherits:
BaseReporter
  • Object
show all
Includes:
Minitest::RelativePosition
Defined in:
lib/minitest/reporters/default_reporter.rb

Overview

A reporter identical to the standard Minitest reporter except with more colors.

Based upon Ryan Davis of Seattle.rb's Minitest (MIT License).

See Also:

Constant Summary

Constants included from Minitest::RelativePosition

Minitest::RelativePosition::INFO_PADDING, Minitest::RelativePosition::MARK_SIZE, Minitest::RelativePosition::TEST_PADDING, Minitest::RelativePosition::TEST_SIZE

Instance Attribute Summary

Attributes inherited from BaseReporter

#tests

Instance Method Summary collapse

Methods inherited from BaseReporter

#add_defaults, #after_test

Constructor Details

#initialize(options = {}) ⇒ DefaultReporter

Returns a new instance of DefaultReporter.



14
15
16
17
18
19
20
21
# File 'lib/minitest/reporters/default_reporter.rb', line 14

def initialize(options = {})
  super
  @detailed_skip = options.fetch(:detailed_skip, true)
  @slow_count = options.fetch(:slow_count, 0)
  @slow_suite_count = options.fetch(:slow_suite_count, 0)
  @fast_fail = options.fetch(:fast_fail, false)
  @options = options
end

Instance Method Details

#before_test(test)



30
31
32
33
# File 'lib/minitest/reporters/default_reporter.rb', line 30

def before_test(test)
  super
  print "\n#{test.class}##{test.name} " if options[:verbose]
end


99
100
101
# File 'lib/minitest/reporters/default_reporter.rb', line 99

def print_failure(test)
  puts colored_for(result(test), message_for(test))
end

#record(test)



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/minitest/reporters/default_reporter.rb', line 35

def record(test)
  super

  print "#{"%.2f" % test.time} = " if options[:verbose]

  print(if test.passed?
    green('.')
  elsif test.skipped?
    yellow('S')
  elsif test.failure
    red('F')
  end)

  if @fast_fail && (test.skipped? || test.failure)
    puts
    print_failure(test)
  end
end

#report



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
# File 'lib/minitest/reporters/default_reporter.rb', line 54

def report
  super
  status_line = "Finished tests in %.6fs, %.4f tests/s, %.4f assertions/s." %
    [total_time, count / total_time, assertions / total_time]

  puts
  puts
  puts colored_for(suite_result, status_line)

  unless @fast_fail
    tests.reject(&:passed?).each do |test|
      puts
      print_failure(test)
    end
  end

  if @slow_count > 0
    slow_tests = tests.sort_by(&:time).reverse.take(@slow_count)

    puts
    puts "Slowest tests:"
    puts

    slow_tests.each do |test|
      puts "%.6fs %s" % [test.time, "#{test.name}##{test.class}"]
    end
  end

  if @slow_suite_count > 0
    slow_suites = @suite_times.sort_by { |x| x[1] }.reverse.take(@slow_suite_count)

    puts
    puts "Slowest test classes:"
    puts

    slow_suites.each do |slow_suite|
      puts "%.6fs %s" % [slow_suite[1], slow_suite[0]]
    end
  end

  puts
  print colored_for(suite_result, result_line)
  puts
end

#start



23
24
25
26
27
28
# File 'lib/minitest/reporters/default_reporter.rb', line 23

def start
  super
  puts
  puts "# Running tests:"
  puts
end