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.
- data/lib/top_tests/version.rb +1 -1
- data/lib/top_tests.rb +32 -3
- metadata +1 -1
data/lib/top_tests/version.rb
CHANGED
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.
|
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)
|
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
|
-
|