Class: Minitest::TopTestReporter
- Inherits:
-
AbstractReporter
- Object
- AbstractReporter
- Minitest::TopTestReporter
- Defined in:
- lib/minitest/top_tests_plugin.rb
Instance Attribute Summary collapse
-
#max_time ⇒ Object
readonly
Returns the value of attribute max_time.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #format_tests(tests) ⇒ Object
-
#initialize(options) ⇒ TopTestReporter
constructor
A new instance of TopTestReporter.
- #passed? ⇒ Boolean
- #print_slow_tests ⇒ Object
- #record(result) ⇒ Object
- #report ⇒ Object
- #slow_tests ⇒ Object
- #slowest_results ⇒ Object
Constructor Details
#initialize(options) ⇒ TopTestReporter
Returns a new instance of TopTestReporter.
15 16 17 18 |
# File 'lib/minitest/top_tests_plugin.rb', line 15 def initialize() @results = [] @max_time = [:max_time] end |
Instance Attribute Details
#max_time ⇒ Object (readonly)
Returns the value of attribute max_time.
13 14 15 |
# File 'lib/minitest/top_tests_plugin.rb', line 13 def max_time @max_time end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
13 14 15 |
# File 'lib/minitest/top_tests_plugin.rb', line 13 def results @results end |
Instance Method Details
#format_tests(tests) ⇒ Object
56 57 58 |
# File 'lib/minitest/top_tests_plugin.rb', line 56 def format_tests(tests) tests.map { |t| " #{format("%7.3f", t.time)} #{t.klass}##{t.name}" }.join("\n") end |
#passed? ⇒ Boolean
25 26 27 |
# File 'lib/minitest/top_tests_plugin.rb', line 25 def passed? slow_tests.empty? end |
#print_slow_tests ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/minitest/top_tests_plugin.rb', line 45 def print_slow_tests if !slow_tests.empty? if slow_tests.size == 1 puts "\n1 test is taking longer than #{max_time} seconds:" else puts "\n3 tests are taking longer than #{max_time} seconds:" end puts format_tests(slow_tests) end end |
#record(result) ⇒ Object
20 21 22 23 |
# File 'lib/minitest/top_tests_plugin.rb', line 20 def record(result) results << result #result.refute(true, "Too long") if max_time && result.time > max_time end |
#report ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/minitest/top_tests_plugin.rb', line 29 def report if slow_tests.empty? puts "\nTop 10 slowest tests:\n#{format_tests(slowest_results[0,10])}" else print_slow_tests end end |
#slow_tests ⇒ Object
41 42 43 |
# File 'lib/minitest/top_tests_plugin.rb', line 41 def slow_tests max_time ? results.find_all { |r| r.time > max_time } : [] end |
#slowest_results ⇒ Object
37 38 39 |
# File 'lib/minitest/top_tests_plugin.rb', line 37 def slowest_results results.sort { |a, b| b.time <=> a.time } end |