Class: Minitest::Reporters::ProgressReporter

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

Overview

Fuubar-like reporter with a progress bar.

Based upon Jeff Kreefmeijer's Fuubar (MIT License) and paydro's monkey-patch.

Constant Summary collapse

PROGRESS_MARK =
'='.freeze

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 = {}) ⇒ ProgressReporter

Returns a new instance of ProgressReporter.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/minitest/reporters/progress_reporter.rb', line 18

def initialize(options = {})
  super
  @detailed_skip = options.fetch(:detailed_skip, true)

  @progress = ProgressBar.create(
    total:          total_count,
    starting_at:    count,
    progress_mark:  green(PROGRESS_MARK),
    remainder_mark: ' ',
    format:         options.fetch(:format, '  %C/%c: [%B] %p%% %a, %e'),
    autostart:      false
  )
end

Instance Method Details

#before_test(test)



41
42
43
44
45
46
47
# File 'lib/minitest/reporters/progress_reporter.rb', line 41

def before_test(test)
  super
  if options[:verbose]
    puts
    puts("\n%s#%s" % [test_class(test), test.name])
  end
end

#record(test)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/minitest/reporters/progress_reporter.rb', line 49

def record(test)
  super
  return if test.skipped? && !@detailed_skip
  if test.failure
    print "\e[0m\e[1000D\e[K"
    print_colored_status(test)
    print_test_with_time(test)
    puts
    print_info(test.failure, test.error?)
    puts
  end

  if test.skipped? && color != "red"
    self.color = "yellow"
  elsif test.failure
    self.color = "red"
  end

  show
end

#report



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/minitest/reporters/progress_reporter.rb', line 70

def report
  super
  @progress.finish

  puts
  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



32
33
34
35
36
37
38
39
# File 'lib/minitest/reporters/progress_reporter.rb', line 32

def start
  super
  puts('Started with run options %s' % options[:args])
  puts
  @progress.start
  @progress.total = total_count
  show
end