123456789_123456789_123456789_123456789_123456789_

Class: Minitest::ProfileReporter

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, StatisticsReporter
Instance Chain:
self, StatisticsReporter
Inherits: StatisticsReporter
  • ::Object
Defined in: railties/lib/minitest/rails_plugin.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(io = $stdout, options = {}) ⇒ ProfileReporter

[ GitHub ]

  
# File 'railties/lib/minitest/rails_plugin.rb', line 29

def initialize(io = $stdout, options = {})
  super
  @results = []
  @count = options[:profile]
end

Instance Method Details

#record(result)

[ GitHub ]

  
# File 'railties/lib/minitest/rails_plugin.rb', line 35

def record(result)
  @results << result
end

#report

[ GitHub ]

  
# File 'railties/lib/minitest/rails_plugin.rb', line 39

def report
  total_time = @results.sum(&:time)

  @results.sort! { |a, b| b.time <=> a.time }
  slow_results = @results.take(@count)
  slow_tests_total_time = slow_results.sum(&:time)

  ratio = (total_time == 0) ? 0.0 : (slow_tests_total_time / total_time) * 100

  io.puts("\nTop %d slowest tests (%.2f seconds, %.1f%% of total time):\n" % [slow_results.size, slow_tests_total_time, ratio])
  slow_results.each do |result|
    io.puts("  %s\n    %.4f seconds %s\n" % [result.location, result.time, source_location(result)])
  end
  io.puts("\n")
end

#source_location(result) (private)

[ GitHub ]

  
# File 'railties/lib/minitest/rails_plugin.rb', line 56

def source_location(result)
  filename, line = result.source_location
  return "" unless filename

  pwd = Dir.pwd
  if filename.start_with?(pwd)
    filename = Pathname.new(filename).relative_path_from(pwd)
  end
  "#{filename}:#{line}"
end