Class: Minitest::HogReporter

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

Defined Under Namespace

Classes: Record

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io = STDOUT, options = {}) ⇒ HogReporter

Returns a new instance of HogReporter.



43
44
45
46
47
48
# File 'lib/minitest/hog.rb', line 43

def initialize(io = STDOUT, options = {})
  super
  
  @max_memory = options.fetch(:max_memory, 64)
  @piggy_tests = []
end

Instance Attribute Details

#max_memoryObject (readonly)

Returns the value of attribute max_memory.



41
42
43
# File 'lib/minitest/hog.rb', line 41

def max_memory
  @max_memory
end

#piggy_testsObject (readonly)

Returns the value of attribute piggy_tests.



41
42
43
# File 'lib/minitest/hog.rb', line 41

def piggy_tests
  @piggy_tests
end

Instance Method Details

#record(result) ⇒ Object



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

def record result
  if result.memory_used > max_memory
    piggy_tests << Record.new(result.location, result.memory_used)
  end
end

#reportObject



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

def report
  return if piggy_tests.empty?
  
  piggy_tests.sort_by!{|r| -r.memory_used}
  
  io.puts
  io.puts "#{piggy_tests.length} hogs."
  piggy_tests.each_with_index do |record, i|
    io.puts "%3d) %s: %i kb" % [i+1, record.location, record.memory_used]
  end
end