Class: Minitest::SnailReporter

Inherits:
Reporter
  • Object
show all
Defined in:
lib/minitest/snail_reporter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io = STDOUT, options = self.class.options) ⇒ SnailReporter

Returns a new instance of SnailReporter.



20
21
22
23
24
25
# File 'lib/minitest/snail_reporter.rb', line 20

def initialize(io = STDOUT, options = self.class.options)
  super
  
  @max_duration = options.fetch(:max_duration)
  @slow_tests = []
end

Instance Attribute Details

#max_durationObject (readonly)

Returns the value of attribute max_duration.



3
4
5
# File 'lib/minitest/snail_reporter.rb', line 3

def max_duration
  @max_duration
end

#slow_testsObject (readonly)

Returns the value of attribute slow_tests.



3
4
5
# File 'lib/minitest/snail_reporter.rb', line 3

def slow_tests
  @slow_tests
end

Class Method Details

.enable!(options = {}) ⇒ Object



11
12
13
14
# File 'lib/minitest/snail_reporter.rb', line 11

def self.enable!(options = {})
  @enabled = true
  self.options.merge!(options)
end

.enabled?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/minitest/snail_reporter.rb', line 16

def self.enabled?
  @enabled ||= false
end

.optionsObject



5
6
7
8
9
# File 'lib/minitest/snail_reporter.rb', line 5

def self.options
  @default_options ||= {
    :max_duration => 2
  }
end

Instance Method Details

#record(result) ⇒ Object



27
28
29
# File 'lib/minitest/snail_reporter.rb', line 27

def record result
  slow_tests << result if result.time > max_duration
end

#reportObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/minitest/snail_reporter.rb', line 31

def report
  return if slow_tests.empty?
  
  slow_tests.sort_by!{|r| -r.time}
  
  io.puts
  io.puts "#{slow_tests.length} slow tests."
  slow_tests.each_with_index do |result, i|
    io.puts "%3d) %s: %.2f s" % [i+1, result.location, result.time]
  end
end