Class: Minitest::Heat::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/heat/timer.rb

Overview

Provides a timer to keep track of the full test suite duration and provide convenient methods

for calculating tests/second and assertions/second

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeself

Creates an instance of a timer to be used for the duration of a test suite run



13
14
15
16
17
18
19
# File 'lib/minitest/heat/timer.rb', line 13

def initialize
  @test_count = 0
  @assertion_count = 0

  @start_time = nil
  @stop_time = nil
end

Instance Attribute Details

#assertion_countObject (readonly)

Returns the value of attribute assertion_count.



8
9
10
# File 'lib/minitest/heat/timer.rb', line 8

def assertion_count
  @assertion_count
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



8
9
10
# File 'lib/minitest/heat/timer.rb', line 8

def start_time
  @start_time
end

#stop_timeObject (readonly)

Returns the value of attribute stop_time.



8
9
10
# File 'lib/minitest/heat/timer.rb', line 8

def stop_time
  @stop_time
end

#test_countObject (readonly)

Returns the value of attribute test_count.



8
9
10
# File 'lib/minitest/heat/timer.rb', line 8

def test_count
  @test_count
end

Instance Method Details

#assertions_per_secondFloat

Provides a nice rounded answer for about how many assertions were completed per second

Returns:

  • (Float)

    the average number of assertions completed per second



65
66
67
# File 'lib/minitest/heat/timer.rb', line 65

def assertions_per_second
  (assertion_count / total_time).round(2)
end

#increment_counts(count) ⇒ void

This method returns an undefined value.

Records the test and assertion counts for a given test outcome

Parameters:

  • count (Integer)

    the number of assertions from the test



50
51
52
53
# File 'lib/minitest/heat/timer.rb', line 50

def increment_counts(count)
  @test_count += 1
  @assertion_count += count
end

#start!Float

Records the start time for the full test suite using ‘Minitest.clock_time`

Returns:

  • (Float)

    the Minitest.clock_time



24
25
26
# File 'lib/minitest/heat/timer.rb', line 24

def start!
  @start_time = Minitest.clock_time
end

#stop!Float

Records the stop time for the full test suite using ‘Minitest.clock_time`

Returns:

  • (Float)

    the Minitest.clock_time



31
32
33
# File 'lib/minitest/heat/timer.rb', line 31

def stop!
  @stop_time = Minitest.clock_time
end

#tests_per_secondFloat

Provides a nice rounded answer for about how many tests were completed per second

Returns:

  • (Float)

    the average number of tests completed per second



58
59
60
# File 'lib/minitest/heat/timer.rb', line 58

def tests_per_second
  (test_count / total_time).round(2)
end

#total_timeFloat

Calculates the total time take for the full test suite to run while ensuring it never

returns a zero that would be problematic as a denomitor in calculating average times

Returns:

  • (Float)

    the clocktime duration of the test suite run in seconds



39
40
41
42
43
44
# File 'lib/minitest/heat/timer.rb', line 39

def total_time
  # Don't return 0. The time can end up being 0 for a new or realy fast test suite, and
  # dividing by 0 doesn't go well when determining average time, so this ensures it uses a
  # close-enough-but-not-zero value.
  delta.zero? ? 0.01 : delta
end