top_tests 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4b6aabd772a5ac50d25397f467c6c2a7a404a74
4
- data.tar.gz: 3b8c32a8cae90c70e40b3e1c1b150e5114fc7344
3
+ metadata.gz: 6a3d5d5040a23de5ce945733891767805da6cb8b
4
+ data.tar.gz: 8febea984183a212044d648d1864f59ef397e361
5
5
  SHA512:
6
- metadata.gz: 1850eead7b6d5a6c8f24f4a31630b963ee67ce1717755d6ee6a551264e4853d7e5acfee3d164e0e99f94326748f84ffd0562cad6684e2d19a11dc7280cc0a525
7
- data.tar.gz: a5da7dedbc8d8315b6b28e54d0dc91cc3f628e6115bc87c15cea593eefef71416e1cd611e759faa07292e9428d51a6ea0e6ae2218c4a5101dbd45ba0e4abdfee
6
+ metadata.gz: e7346f647573e30a4d183a3932cc2ccecba853b443d5eff0ba23b24810aa2dae0d63e810a14b229b2e6e30938fd0271c98f56dcd1bb72723cf2e398ef4f18d70
7
+ data.tar.gz: 8be5772786b68b6018854bd4b96ab118bd3f807729b4c32a8a800677859371c91681f52432aa7501ef87836bc1cad16792a6a8d52ece1a3a705d9427d984b9cf
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in top_tests.gemspec
4
4
  gemspec
5
5
 
6
- gem 'minitest', '>= 2.11.2'
6
+ gem 'minitest', '>= 5.10.2'
data/Gemfile.lock CHANGED
@@ -1,16 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- top_tests (0.0.4)
4
+ top_tests (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- minitest (3.5.0)
9
+ minitest (5.10.2)
10
10
 
11
11
  PLATFORMS
12
12
  ruby
13
13
 
14
14
  DEPENDENCIES
15
- minitest (>= 2.11.2)
15
+ minitest (>= 5.10.2)
16
16
  top_tests!
17
+
18
+ BUNDLED WITH
19
+ 1.13.6
data/README.rdoc CHANGED
@@ -4,8 +4,6 @@ keeping your tests fast.
4
4
 
5
5
  Moreover top tests can break your build if any test is taking longer than a specified duration.
6
6
 
7
- Since version 0.0.4, Top tests works only with Ruby 2.0 and Rails 4.0
8
-
9
7
  == How to use it?
10
8
  Add to your Gemfile.
11
9
 
@@ -13,16 +11,7 @@ Add to your Gemfile.
13
11
  gem 'top_tests'
14
12
  end
15
13
 
16
- Then require top tests and just include it into your test class:
17
-
18
- class SampleTest < MiniTest::Unit::TestCase
19
- include TopTests
20
-
21
- # Break your build if any test's duration is longer than ...
22
- self.max_duration = 0.5 # Optional, nil by default (in seconds)
23
- end
24
-
25
- Sample output:
14
+ Then run your test as usual and you will have a similar output:
26
15
 
27
16
  Top 10 slowest tests:
28
17
  0.429 ApplicationControllerTest#test_notify_error
@@ -36,9 +25,9 @@ Sample output:
36
25
  0.091 SuricatsControllerTest#test_destroy
37
26
  0.090 HoneyBadgersControllerTest#test_show
38
27
 
39
- Sample output when few tests are too slow:
28
+ Run your your with the option `--max-time=SECONDS` to break the tests that are slower than the specified time:
40
29
 
41
- TEST?FAIL! 3 test(s) are taking longer than 0.2 seconds:
30
+ 3 tests are taking longer than 0.2 seconds:
42
31
  0.410 HoneyBadgerTest#test_fighting_a_cobra
43
32
  0.228 SuricatTest#test_caught_by_an_eagle
44
33
  0.203 HoneyBadgerTest#test_eating_larvae
@@ -0,0 +1,60 @@
1
+ module Minitest
2
+ def self.plugin_top_tests_init(options)
3
+ self.reporter << TopTestReporter.new(options)
4
+ end
5
+
6
+ def self.plugin_top_tests_options(opts, options)
7
+ opts.on "--max-time=ms", "Test fails if it exceeds specified time in seconds" do |max_time|
8
+ options[:max_time] = max_time.to_f
9
+ end
10
+ end
11
+
12
+ class TopTestReporter < AbstractReporter
13
+ attr_reader :results, :max_time
14
+
15
+ def initialize(options)
16
+ @results = []
17
+ @max_time = options[:max_time]
18
+ end
19
+
20
+ def record(result)
21
+ results << result
22
+ #result.refute(true, "Too long") if max_time && result.time > max_time
23
+ end
24
+
25
+ def passed?
26
+ slow_tests.empty?
27
+ end
28
+
29
+ def report
30
+ if slow_tests.empty?
31
+ puts "\nTop 10 slowest tests:\n#{format_tests(slowest_results[0,10])}"
32
+ else
33
+ print_slow_tests
34
+ end
35
+ end
36
+
37
+ def slowest_results
38
+ results.sort { |a, b| b.time <=> a.time }
39
+ end
40
+
41
+ def slow_tests
42
+ max_time ? results.find_all { |r| r.time > max_time } : []
43
+ end
44
+
45
+ def print_slow_tests
46
+ if !slow_tests.empty?
47
+ if slow_tests.size == 1
48
+ puts "\n1 test is taking longer than #{max_time} seconds:"
49
+ else
50
+ puts "\n3 tests are taking longer than #{max_time} seconds:"
51
+ end
52
+ puts format_tests(slow_tests)
53
+ end
54
+ end
55
+
56
+ def format_tests(tests)
57
+ tests.map { |t| " #{format("%7.3f", t.time)} #{t.class}##{t.name}" }.join("\n")
58
+ end
59
+ end
60
+ end
@@ -1,8 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module TopTests
4
-
5
- VERSION = '0.0.6'.freeze
6
-
4
+ VERSION = '0.1.0'.freeze
7
5
  end
8
6
 
data/test/failing_test.rb CHANGED
@@ -4,11 +4,7 @@ require 'minitest/autorun'
4
4
  require 'top_tests'
5
5
 
6
6
  class FailingTest < MiniTest::Unit::TestCase
7
-
8
- include TopTests
9
-
10
7
  def test_bad
11
8
  assert(false)
12
9
  end
13
-
14
10
  end
data/test/fast_test.rb CHANGED
@@ -4,13 +4,7 @@ require 'minitest/autorun'
4
4
  require 'top_tests'
5
5
 
6
6
  class FastTest < MiniTest::Unit::TestCase
7
-
8
- include TopTests
9
-
10
- self.max_duration = 0.5
11
-
12
7
  def test_good
13
8
  sleep(0.499)
14
9
  end
15
-
16
10
  end
data/test/slow_test.rb CHANGED
@@ -4,11 +4,6 @@ require 'minitest/autorun'
4
4
  require 'top_tests'
5
5
 
6
6
  class SlowTest < MiniTest::Unit::TestCase
7
-
8
- include TopTests
9
-
10
- self.max_duration = 0.5
11
-
12
7
  def test_good
13
8
  sleep(0.5)
14
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: top_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-20 00:00:00.000000000 Z
11
+ date: 2017-05-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Top tests lists the 10 slowest tests after execution
14
14
  email:
@@ -23,6 +23,7 @@ files:
23
23
  - LICENSE
24
24
  - README.rdoc
25
25
  - Rakefile
26
+ - lib/minitest/top_tests_plugin.rb
26
27
  - lib/top_tests.rb
27
28
  - lib/top_tests/version.rb
28
29
  - test/failing_test.rb
@@ -53,3 +54,4 @@ signing_key:
53
54
  specification_version: 4
54
55
  summary: Top tests lists the 10 slowest tests after execution
55
56
  test_files: []
57
+ has_rdoc: