top_tests 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/Gemfile +1 -1
 - data/Gemfile.lock +6 -3
 - data/README.rdoc +3 -14
 - data/lib/minitest/top_tests_plugin.rb +60 -0
 - data/lib/top_tests/version.rb +1 -3
 - data/test/failing_test.rb +0 -4
 - data/test/fast_test.rb +0 -6
 - data/test/slow_test.rb +0 -5
 - metadata +4 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 6a3d5d5040a23de5ce945733891767805da6cb8b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8febea984183a212044d648d1864f59ef397e361
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: e7346f647573e30a4d183a3932cc2ccecba853b443d5eff0ba23b24810aa2dae0d63e810a14b229b2e6e30938fd0271c98f56dcd1bb72723cf2e398ef4f18d70
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 8be5772786b68b6018854bd4b96ab118bd3f807729b4c32a8a800677859371c91681f52432aa7501ef87836bc1cad16792a6a8d52ece1a3a705d9427d984b9cf
         
     | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -1,16 +1,19 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            PATH
         
     | 
| 
       2 
2 
     | 
    
         
             
              remote: .
         
     | 
| 
       3 
3 
     | 
    
         
             
              specs:
         
     | 
| 
       4 
     | 
    
         
            -
                top_tests (0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
                top_tests (0.0.6)
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            GEM
         
     | 
| 
       7 
7 
     | 
    
         
             
              remote: http://rubygems.org/
         
     | 
| 
       8 
8 
     | 
    
         
             
              specs:
         
     | 
| 
       9 
     | 
    
         
            -
                minitest ( 
     | 
| 
      
 9 
     | 
    
         
            +
                minitest (5.10.2)
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
            PLATFORMS
         
     | 
| 
       12 
12 
     | 
    
         
             
              ruby
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
            DEPENDENCIES
         
     | 
| 
       15 
     | 
    
         
            -
              minitest (>=  
     | 
| 
      
 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  
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
            Run your your with the option `--max-time=SECONDS` to break the tests that are slower than the specified time:
         
     | 
| 
       40 
29 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                 
     | 
| 
      
 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
         
     | 
    
        data/lib/top_tests/version.rb
    CHANGED
    
    
    
        data/test/failing_test.rb
    CHANGED
    
    
    
        data/test/fast_test.rb
    CHANGED
    
    
    
        data/test/slow_test.rb
    CHANGED
    
    
    
        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 
     | 
| 
      
 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:  
     | 
| 
      
 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: 
         
     |