Class: MiniTest::Reporters::ProgressReporter

Inherits:
Object
  • Object
show all
Includes:
ANSI::Code, MiniTest::Reporter
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

INFO_PADDING =
2

Instance Method Summary collapse

Methods included from MiniTest::Reporter

#after_suite, #before_suite, #before_test, #filter_backtrace, #output, #pass, #print, #puts, #runner, #verbose?

Constructor Details

#initialize(options = {}) ⇒ ProgressReporter

Returns a new instance of ProgressReporter.



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

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

  @progress = PowerBar.new(:msg => "0/#{runner.test_count}")
  @progress.settings.tty.finite.output = lambda { |s| print(s) }
  @progress.settings.tty.finite.template.barchar = "="
  @progress.settings.tty.finite.template.padchar = " "
  @progress.settings.tty.finite.template.pre = "\e[1000D\e[?25l#{GREEN}"
  @progress.settings.tty.finite.template.post = CLEAR
end

Instance Method Details

#after_suites(suites, type)



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/minitest/reporters/progress_reporter.rb', line 91

def after_suites(suites, type)
  @progress.close

  total_time = Time.now - runner.suites_start_time

  wipe
  puts
  puts('Finished in %.5fs' % total_time)
  print('%d tests, %d assertions, ' % [runner.test_count, runner.assertion_count])
  print(red { '%d failures, %d errors, ' } % [runner.failures, runner.errors])
  print(yellow { '%d skips' } % runner.skips)
  puts
end

#after_test(suite, test)



53
54
55
# File 'lib/minitest/reporters/progress_reporter.rb', line 53

def after_test(suite, test)
  increment
end

#before_suites(suites, type)



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

def before_suites(suites, type)
  puts 'Started'
  puts

  @finished_count = 0
  show
end

#error(suite, test, test_runner)



80
81
82
83
84
85
86
87
88
89
# File 'lib/minitest/reporters/progress_reporter.rb', line 80

def error(suite, test, test_runner)
  wipe
  print(red { 'ERROR' })
  print_test_with_time(suite, test)
  puts
  print_info(test_runner.exception)
  puts

  self.color = RED
end

#failure(suite, test, test_runner)



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

def failure(suite, test, test_runner)
  wipe
  print(red { 'FAIL' })
  print_test_with_time(suite, test)
  puts
  print_info(test_runner.exception, false)
  puts

  self.color = RED
end

#increment



38
39
40
41
# File 'lib/minitest/reporters/progress_reporter.rb', line 38

def increment
  @finished_count += 1
  show
end

#show



43
44
45
46
47
48
49
50
51
# File 'lib/minitest/reporters/progress_reporter.rb', line 43

def show
  return if runner.test_count == 0

  @progress.show({
    :msg => "#{@finished_count}/#{runner.test_count}",
    :done => @finished_count,
    :total => runner.test_count,
  }, true)
end

#skip(suite, test, test_runner)



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/minitest/reporters/progress_reporter.rb', line 57

def skip(suite, test, test_runner)
  if @detailed_skip
    wipe
    print(yellow { 'SKIP' })
    print_test_with_time(suite, test)
    puts
    puts
  end

  self.color = YELLOW unless color == RED
end