Class: Minitest::TestProfile::Reporter
- Inherits:
-
StatisticsReporter
- Object
- StatisticsReporter
- Minitest::TestProfile::Reporter
- Defined in:
- lib/minitest/test_profile/reporter.rb
Instance Attribute Summary collapse
-
#test_results ⇒ Object
readonly
Returns the value of attribute test_results.
Instance Method Summary collapse
- #aggregate_slow_tests! ⇒ Object
- #calculate_total_time ⇒ Object
- #display_aggregated_results ⇒ Object
-
#initialize(io = $stdout, options = {}) ⇒ Reporter
constructor
A new instance of Reporter.
- #ratio ⇒ Object
- #record(result) ⇒ Object
- #report ⇒ Object
- #slow_tests_total_time ⇒ Object
Constructor Details
#initialize(io = $stdout, options = {}) ⇒ Reporter
Returns a new instance of Reporter.
6 7 8 9 10 11 |
# File 'lib/minitest/test_profile/reporter.rb', line 6 def initialize(io = $stdout, = {}) super(io, ) @test_results = [] @count = [:count].to_i @calculated_total_time = nil end |
Instance Attribute Details
#test_results ⇒ Object (readonly)
Returns the value of attribute test_results.
4 5 6 |
# File 'lib/minitest/test_profile/reporter.rb', line 4 def test_results @test_results end |
Instance Method Details
#aggregate_slow_tests! ⇒ Object
34 35 36 37 |
# File 'lib/minitest/test_profile/reporter.rb', line 34 def aggregate_slow_tests! @test_results.sort! { |a, b| b.time <=> a.time } @test_results = @test_results.take(@count) end |
#calculate_total_time ⇒ Object
30 31 32 |
# File 'lib/minitest/test_profile/reporter.rb', line 30 def calculate_total_time @calculated_total_time ||= @test_results.inject(0) { |sum, slow_test| sum + slow_test.time } end |
#display_aggregated_results ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/minitest/test_profile/reporter.rb', line 21 def display_aggregated_results calculate_total_time aggregate_slow_tests! io.puts "\nTop %d slowest tests (%.6f seconds, %.1f%% of total time):\n" % [@test_results.size, slow_tests_total_time, ratio] @test_results.each do |test_result| io.puts "%s\n %.2f seconds\n" % [test_result.location, test_result.time] end end |
#ratio ⇒ Object
43 44 45 |
# File 'lib/minitest/test_profile/reporter.rb', line 43 def ratio (slow_tests_total_time / @calculated_total_time) * 100 end |
#record(result) ⇒ Object
17 18 19 |
# File 'lib/minitest/test_profile/reporter.rb', line 17 def record(result) @test_results << result end |
#report ⇒ Object
13 14 15 |
# File 'lib/minitest/test_profile/reporter.rb', line 13 def report display_aggregated_results end |
#slow_tests_total_time ⇒ Object
39 40 41 |
# File 'lib/minitest/test_profile/reporter.rb', line 39 def slow_tests_total_time @slow_tests_total_time ||= @test_results.inject(0) { |sum, slow_test| sum + slow_test.time } end |