Class: Minitest::ProfileReporter

Inherits:
AbstractReporter
  • Object
show all
Defined in:
lib/minitest/profile_plugin.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ProfileReporter

Returns a new instance of ProfileReporter.



20
21
22
23
# File 'lib/minitest/profile_plugin.rb', line 20

def initialize(options)
  self.io = options[:io]
  self.results = []
end

Instance Attribute Details

#ioObject

Returns the value of attribute io.



18
19
20
# File 'lib/minitest/profile_plugin.rb', line 18

def io
  @io
end

#resultsObject

Returns the value of attribute results.



18
19
20
# File 'lib/minitest/profile_plugin.rb', line 18

def results
  @results
end

Instance Method Details

#record(result) ⇒ Object



25
26
27
# File 'lib/minitest/profile_plugin.rb', line 25

def record(result)
  results << [result.time, result.location]
end

#reportObject



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

def report
  return unless passed?
  puts
  puts "=" * 80
  puts "Your 10 Slowest Tests"
  puts "=" * 80
  puts
  sorted_results[0,10].each do |time, test_name|
    puts "#{sprintf("%7.4f",time)}ms - #{test_name}"
  end

  puts
end

#sorted_resultsObject



43
44
45
# File 'lib/minitest/profile_plugin.rb', line 43

def sorted_results
  results.sort { |a, b| b[0] <=> a[0] }
end