Class: Minitest::ProfileReporter
- Inherits:
-
StatisticsReporter
- Object
- StatisticsReporter
- Minitest::ProfileReporter
- Defined in:
- lib/minitest/rails_plugin.rb
Instance Method Summary collapse
-
#initialize(io = $stdout, options = {}) ⇒ ProfileReporter
constructor
A new instance of ProfileReporter.
- #record(result) ⇒ Object
- #report ⇒ Object
Constructor Details
#initialize(io = $stdout, options = {}) ⇒ ProfileReporter
Returns a new instance of ProfileReporter.
29 30 31 32 33 |
# File 'lib/minitest/rails_plugin.rb', line 29 def initialize(io = $stdout, = {}) super @results = [] @count = [:profile] end |
Instance Method Details
#record(result) ⇒ Object
35 36 37 |
# File 'lib/minitest/rails_plugin.rb', line 35 def record(result) @results << result end |
#report ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File '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 |