top_tests 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  module TopTests
4
4
 
5
- VERSION = '0.0.1'.freeze
5
+ VERSION = '0.0.2'.freeze
6
6
 
7
7
  end
8
8
 
data/lib/top_tests.rb CHANGED
@@ -10,7 +10,7 @@ module TopTests
10
10
  klass.setup :start_timer
11
11
  klass.teardown :stop_timer
12
12
  klass.extend(ClassMethods)
13
- at_exit { at_exit { klass.print_top_tests } }
13
+ at_exit { at_exit { klass.at_exit_callback } }
14
14
  end
15
15
 
16
16
  ########################
@@ -35,16 +35,45 @@ module TopTests
35
35
  @@tests_durations ||= []
36
36
  end
37
37
 
38
+ def max_duration=(seconds)
39
+ @@max_duration = seconds
40
+ end
41
+
42
+ def max_duration
43
+ @@max_duration
44
+ end
45
+
38
46
  def top_tests
39
47
  tests_durations.sort { |a, b| b.last <=> a.last }
40
48
  end
41
49
 
50
+ def slow_tests
51
+ max_duration ? top_tests.find_all { |t| top_tests.first.last > max_duration } : []
52
+ end
53
+
54
+ def format_tests(tests)
55
+ tests.map { |t| " #{format("%7.3f", t.last)} #{t.first}" }.join("\n")
56
+ end
57
+
42
58
  def print_top_tests
43
59
  puts "\nTop tests:"
44
- puts top_tests.shift(10).map { |t| "#{format("%7.3f", t.last)} #{t.first}" }.join("\n")
60
+ puts format_tests(top_tests.shift(10))
45
61
  puts
46
62
  end
63
+
64
+ def check_tests_duration
65
+ if !slow_tests.empty?
66
+ puts "\nTEST?FAIL! #{slow_tests.count} test(s) are taking longer than #{max_duration} seconds:"
67
+ puts format_tests(top_tests)
68
+ puts
69
+ exit 1
70
+ end
71
+ end
72
+
73
+ def at_exit_callback
74
+ check_tests_duration
75
+ print_top_tests
76
+ end
47
77
  end
48
78
 
49
79
  end
50
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: top_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: