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].to_i
  @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



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_timeObject



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_resultsObject



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

#ratioObject



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

#reportObject



13
14
15
# File 'lib/minitest/test_profile/reporter.rb', line 13

def report
  display_aggregated_results
end

#slow_tests_total_timeObject



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