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
- #count ⇒ 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] @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
36 37 38 39 |
# File 'lib/minitest/test_profile/reporter.rb', line 36 def aggregate_slow_tests! @test_results.sort! { |a, b| b.time <=> a.time } @test_results = @test_results.take(count) end |
#calculate_total_time ⇒ Object
32 33 34 |
# File 'lib/minitest/test_profile/reporter.rb', line 32 def calculate_total_time @calculated_total_time ||= @test_results.inject(0) { |sum, slow_test| sum + slow_test.time } end |
#count ⇒ Object
50 51 52 |
# File 'lib/minitest/test_profile/reporter.rb', line 50 def count @count || Minitest::TestProfile.count end |
#display_aggregated_results ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/minitest/test_profile/reporter.rb', line 23 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
45 46 47 48 |
# File 'lib/minitest/test_profile/reporter.rb', line 45 def ratio return 0.0 if @calculated_total_time == 0 (slow_tests_total_time / @calculated_total_time) * 100 end |
#record(result) ⇒ Object
18 19 20 21 |
# File 'lib/minitest/test_profile/reporter.rb', line 18 def record(result) return unless Minitest::TestProfile.use? @test_results << result end |
#report ⇒ Object
13 14 15 16 |
# File 'lib/minitest/test_profile/reporter.rb', line 13 def report return unless Minitest::TestProfile.use? display_aggregated_results end |
#slow_tests_total_time ⇒ Object
41 42 43 |
# File 'lib/minitest/test_profile/reporter.rb', line 41 def slow_tests_total_time @slow_tests_total_time ||= @test_results.inject(0) { |sum, slow_test| sum + slow_test.time } end |