Class: Minitest::TestProfile::Reporter

Inherits:
StatisticsReporter
  • Object
show all
Defined in:
lib/minitest/test_profile/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  super(io, options)
  @test_results = []
  @count = options[:count]
  @calculated_total_time = nil
end

Instance Attribute Details

#test_resultsObject (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_timeObject



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

#countObject



50
51
52
# File 'lib/minitest/test_profile/reporter.rb', line 50

def count
  @count || Minitest::TestProfile.count
end

#display_aggregated_resultsObject



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

#ratioObject



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

#reportObject



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_timeObject



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