Class: Minitest::Reporters::DefaultReporter

Inherits:
BaseReporter
  • Object
show all
Includes:
Minitest::RelativePosition, ANSI::Code
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:

Direct Known Subclasses

MeanTimeReporter

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 included from ANSI::Code

#black, color?

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
22
23
24
# 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)
  @suite_times = []
  @suite_start_times = {}
  @fast_fail = options.fetch(:fast_fail, false)
  @show_test_location = options.fetch(:location, false)
  @options = options
end

Instance Method Details

#after_suite(suite) ⇒ Object



47
48
49
50
51
# File 'lib/minitest/reporters/default_reporter.rb', line 47

def after_suite(suite)
  super
  duration = suite_duration(suite)
  @suite_times << [suite.name, duration]
end

#before_suite(suite) ⇒ Object



42
43
44
45
# File 'lib/minitest/reporters/default_reporter.rb', line 42

def before_suite(suite)
  @suite_start_times[suite] = Minitest::Reporters.clock_time
  super
end

#before_test(test) ⇒ Object



37
38
39
40
# File 'lib/minitest/reporters/default_reporter.rb', line 37

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

#on_record(test) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/minitest/reporters/default_reporter.rb', line 59

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

  # Print the pass/skip/fail mark
  print(if test.passed?
    record_pass(test)
  elsif test.skipped?
    record_skip(test)
  elsif test.failure
    record_failure(test)
  end)

  # Print fast_fail information
  if @fast_fail && (test.skipped? || test.failure)
    print_failure(test)
  end
end

#on_reportObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/minitest/reporters/default_reporter.rb', line 94

def on_report
  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)
  puts

  unless @fast_fail
    tests.reject(&:passed?).each do |test|
      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#%s" % [test.time, test.name, test_class(test)]
    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

#on_startObject



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

def on_start
  puts
  puts("# Running tests with run options %s:" % options[:args])
  puts
end


140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/minitest/reporters/default_reporter.rb', line 140

def print_failure(test)
  message = message_for(test)
  unless message.nil? || message.strip == ''
    puts
    puts colored_for(result(test), message)
    if @show_test_location
      location = get_source_location(test)
      puts "\n\n#{relative_path(location[0])}:#{location[1]}"
    end

  end
end

#record(test) ⇒ Object



53
54
55
56
57
# File 'lib/minitest/reporters/default_reporter.rb', line 53

def record(test)
  super

  on_record(test)
end

#record_failure(record) ⇒ Object



85
86
87
# File 'lib/minitest/reporters/default_reporter.rb', line 85

def record_failure(record)
  red(record.result_code)
end

#record_pass(record) ⇒ Object



77
78
79
# File 'lib/minitest/reporters/default_reporter.rb', line 77

def record_pass(record)
  green(record.result_code)
end

#record_skip(record) ⇒ Object



81
82
83
# File 'lib/minitest/reporters/default_reporter.rb', line 81

def record_skip(record)
  yellow(record.result_code)
end

#reportObject Also known as: to_s



89
90
91
92
# File 'lib/minitest/reporters/default_reporter.rb', line 89

def report
  super
  on_report
end

#startObject



26
27
28
29
# File 'lib/minitest/reporters/default_reporter.rb', line 26

def start
  super
  on_start
end