Class: Minitest::Reporters::SpecReporter

Inherits:
BaseReporter
  • Object
show all
Includes:
Minitest::RelativePosition, ANSI::Code
Defined in:
lib/minitest/reporters/spec_reporter.rb

Overview

Turn-like reporter that reads like a spec.

Based upon TwP's turn (MIT License) and paydro's monkey-patch.

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, #before_test

Constructor Details

#initialize(options = {}) ⇒ SpecReporter

The constructor takes an options hash

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • print_failure_summary (Boolean)

    whether to print the errors at the bottom of the report or inline as they happen.



18
19
20
21
# File 'lib/minitest/reporters/spec_reporter.rb', line 18

def initialize(options = {})
  super
  @print_failure_summary = options[:print_failure_summary]
end

Instance Method Details

#record(test)



50
51
52
53
54
# File 'lib/minitest/reporters/spec_reporter.rb', line 50

def record(test)
  super
  record_print_status(test)
  record_print_failures_if_any(test) unless @print_failure_summary
end

#report



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/minitest/reporters/spec_reporter.rb', line 29

def report
  super
  if @print_failure_summary
    failed_test_groups = tests.reject { |test| test.failures.empty? }
                              .sort_by { |test| [test_class(test).to_s, test.name] }
                              .group_by { |test| test_class(test).to_s }
    unless failed_test_groups.empty?
      print(red('Failures and errors:'))

      failed_test_groups.each { |name, tests| print_failure(name, tests) }
    end
  end

  puts('Finished in %.5fs' % total_time)
  print('%d tests, %d assertions, ' % [count, assertions])
  color = failures.zero? && errors.zero? ? :green : :red
  print(send(color) { '%d failures, %d errors, ' } % [failures, errors])
  print(yellow { '%d skips' } % skips)
  puts
end

#start



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

def start
  super
  puts('Started with run options %s' % options[:args])
  puts
end