Class: Minitest::Heat::Timer
- Inherits:
-
Object
- Object
- Minitest::Heat::Timer
- 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
-
#assertion_count ⇒ Object
readonly
Returns the value of attribute assertion_count.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#stop_time ⇒ Object
readonly
Returns the value of attribute stop_time.
-
#test_count ⇒ Object
readonly
Returns the value of attribute test_count.
Instance Method Summary collapse
-
#assertions_per_second ⇒ Float
Provides a nice rounded answer for about how many assertions were completed per second.
-
#increment_counts(count) ⇒ void
Records the test and assertion counts for a given test outcome.
-
#initialize ⇒ self
constructor
Creates an instance of a timer to be used for the duration of a test suite run.
-
#start! ⇒ Float
Records the start time for the full test suite using ‘Minitest.clock_time`.
-
#stop! ⇒ Float
Records the stop time for the full test suite using ‘Minitest.clock_time`.
-
#tests_per_second ⇒ Float
Provides a nice rounded answer for about how many tests were completed per second.
-
#total_time ⇒ Float
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.
Constructor Details
#initialize ⇒ self
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_count ⇒ Object (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_time ⇒ Object (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_time ⇒ Object (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_count ⇒ Object (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_second ⇒ Float
Provides a nice rounded answer for about how many assertions were 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
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`
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`
31 32 33 |
# File 'lib/minitest/heat/timer.rb', line 31 def stop! @stop_time = Minitest.clock_time end |
#tests_per_second ⇒ Float
Provides a nice rounded answer for about how many tests were 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_time ⇒ Float
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
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 |