knapsack 1.1.1 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82a3d1e780cf286d3b6667fa0f40f5682e98cd1a
4
- data.tar.gz: 5847653114e98c5ee8968c5adccec3cd78bb184d
3
+ metadata.gz: fd1d57912b7ba3dc639a4b4166441fe899ebff3e
4
+ data.tar.gz: f908eebdca1733ab47236c9f7891b2f8381ba9c1
5
5
  SHA512:
6
- metadata.gz: a60b622d9f709724e31c8c5ea2fc2e930bc81d4874691ece036440796b7ad1acfa9b7ca3ea4ce27562a09e0f6c74600316d7e1e18eab786acb3ce5ebab3eb3fa
7
- data.tar.gz: 348418b0b04ef13a48a9fce592a1358e226f9024276a9e715e59f5c24654bb62fc0854634fa5db68bebd4940b66e3025b7295afe7f1868f0ab673ee46d837bc7
6
+ metadata.gz: 4d713250822a9633768ee4d8a003379fad3e98cc50f4ae87f02e254b482709be039d5e9870b4ff88805edb1469cca237be31b744f77612c526cdf70e9c209b55
7
+ data.tar.gz: d2f59a9e4178be5534828ccbcbb4d5db6a4b3bcce191ac82446737a25a0d4bfc69c87f3a2e3a8a8ecfd1158d81134a73c6b80827d09a398b2735a375c164829e
data/.travis.yml CHANGED
@@ -5,15 +5,22 @@ rvm:
5
5
  - 2.0.0
6
6
  - 2.1.5
7
7
  - 2.2.0
8
+ - 2.2.2
8
9
  addons:
9
10
  code_climate:
10
11
  repo_token: 38686058eed480dd0fcf8bce9015733e0bae88e44e30f4a1ac63df8aec2f86d8
11
12
  before_install:
12
13
  - "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
13
14
  script:
15
+ # Test for knapsack gem
14
16
  - bin/print_header.sh "Run specs for Knapsack gem"
15
17
  - bundle exec rspec spec
16
18
 
19
+
20
+ - bin/print_header.sh "------------------------------------------------------"
21
+
22
+
23
+ # Tests for example rspec test suite
17
24
  - bin/print_header.sh "Generate knapsack report"
18
25
  - KNAPSACK_GENERATE_REPORT=true bundle exec rspec --default-path spec_examples --tag focus
19
26
 
@@ -32,11 +39,41 @@ script:
32
39
  - CUSTOM_LOGGER=true KNAPSACK_TEST_FILE_PATTERN="spec_examples/**/*_spec.rb" bundle exec rake knapsack:rspec
33
40
 
34
41
  - bin/print_header.sh "Run specs for custom knapsack report path"
35
- - cp knapsack_rspec_report.json knapsack_custom_report.json
36
- - KNAPSACK_REPORT_PATH="knapsack_custom_report.json" KNAPSACK_TEST_FILE_PATTERN="spec_examples/**/*_spec.rb" bundle exec rake knapsack:rspec
42
+ - cp knapsack_rspec_report.json knapsack_custom_rspec_report.json
43
+ - KNAPSACK_REPORT_PATH="knapsack_custom_rspec_report.json" KNAPSACK_TEST_FILE_PATTERN="spec_examples/**/*_spec.rb" bundle exec rake knapsack:rspec
37
44
 
38
45
  - bin/print_header.sh "Run specs when spec file was removed and still exists in knapsack report json"
39
46
  - rm spec_examples/fast/1_spec.rb
40
47
  - KNAPSACK_TEST_FILE_PATTERN="spec_examples/**/*_spec.rb" bundle exec rake knapsack:rspec
48
+
49
+
50
+ - bin/print_header.sh "------------------------------------------------------"
51
+
52
+
53
+ # Tests for example minitest test suite
54
+ - bin/print_header.sh "Generate knapsack report"
55
+ - KNAPSACK_GENERATE_REPORT=true bundle exec rake test
56
+
57
+ - bin/print_header.sh "Run tests with enabled time offset warning"
58
+ - bundle exec rake test
59
+
60
+ - bin/print_header.sh "Run rake task for the first CI node"
61
+ - CI_NODE_TOTAL=2 CI_NODE_INDEX=0 KNAPSACK_TEST_FILE_PATTERN="test_examples/**/*_test.rb" bundle exec rake knapsack:minitest
62
+ - bin/print_header.sh "Run rake task for the second CI node"
63
+ - CI_NODE_TOTAL=2 CI_NODE_INDEX=1 KNAPSACK_TEST_FILE_PATTERN="test_examples/**/*_test.rb" bundle exec rake knapsack:minitest
64
+
65
+ - bin/print_header.sh "Check passing arguments to minitest. Run verbose tests"
66
+ - KNAPSACK_TEST_FILE_PATTERN="test_examples/**/*_test.rb" bundle exec rake "knapsack:minitest[--verbose]"
67
+
68
+ - bin/print_header.sh "Run tests with custom knapsack logger"
69
+ - CUSTOM_LOGGER=true KNAPSACK_TEST_FILE_PATTERN="test_examples/**/*_test.rb" bundle exec rake knapsack:minitest
70
+
71
+ - bin/print_header.sh "Run tests for custom knapsack report path"
72
+ - cp knapsack_minitest_report.json knapsack_custom_minitest_report.json
73
+ - KNAPSACK_REPORT_PATH="knapsack_custom_minitest_report.json" KNAPSACK_TEST_FILE_PATTERN="test_examples/**/*_test.rb" bundle exec rake knapsack:minitest
74
+
75
+ - bin/print_header.sh "Run tests when test file was removed and still exists in knapsack report json"
76
+ - rm test_examples/fast/unit_test.rb
77
+ - KNAPSACK_TEST_FILE_PATTERN="test_examples/**/*_test.rb" bundle exec rake knapsack:minitest
41
78
  notifications:
42
79
  email: false
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  * TODO
4
4
 
5
+ ### 1.2.0
6
+
7
+ * Add minitest adapter.
8
+ * Fix bug with missing global time execution when tests took less than second.
9
+
10
+ https://github.com/ArturT/knapsack/compare/v1.1.1...v1.2.0
11
+
5
12
  ### 1.1.1
6
13
 
7
14
  * Use `system` instead of `exec` in rake tasks so we can return exit code from command.
data/README.md CHANGED
@@ -31,6 +31,47 @@ Presentations about gem:
31
31
 
32
32
  ![With Knapsack gem](docs/images/with_knapsack.png)
33
33
 
34
+
35
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
36
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
37
+ **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
38
+
39
+ - [Update gem](#update-gem)
40
+ - [Installation](#installation)
41
+ - [Usage](#usage)
42
+ - [Step for RSpec](#step-for-rspec)
43
+ - [Step for Cucumber](#step-for-cucumber)
44
+ - [Step for Minitest](#step-for-minitest)
45
+ - [Custom configuration](#custom-configuration)
46
+ - [Common step](#common-step)
47
+ - [Adding or removing tests](#adding-or-removing-tests)
48
+ - [Setup your CI server](#setup-your-ci-server)
49
+ - [Info about ENV variables](#info-about-env-variables)
50
+ - [Passing arguments to rspec](#passing-arguments-to-rspec)
51
+ - [Passing arguments to cucumber](#passing-arguments-to-cucumber)
52
+ - [Passing arguments to minitest](#passing-arguments-to-minitest)
53
+ - [Info for CircleCI users](#info-for-circleci-users)
54
+ - [Step 1](#step-1)
55
+ - [Step 2](#step-2)
56
+ - [Info for Travis users](#info-for-travis-users)
57
+ - [Step 1](#step-1-1)
58
+ - [Step 2](#step-2-1)
59
+ - [Info for semaphoreapp.com users](#info-for-semaphoreappcom-users)
60
+ - [Step 1](#step-1-2)
61
+ - [Step 2](#step-2-2)
62
+ - [Info for buildkite.com users](#info-for-buildkitecom-users)
63
+ - [Step 1](#step-1-3)
64
+ - [Step 2](#step-2-3)
65
+ - [Gem tests](#gem-tests)
66
+ - [Spec](#spec)
67
+ - [Spec examples](#spec-examples)
68
+ - [Contributing](#contributing)
69
+ - [Acknowledgements](#acknowledgements)
70
+ - [Mentions](#mentions)
71
+
72
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
73
+
74
+
34
75
  ## Update gem
35
76
 
36
77
  Please check [changelog](CHANGELOG.md) before update gem. Knapsack follows [semantic versioning](http://semver.org).
@@ -51,6 +92,10 @@ And then execute:
51
92
 
52
93
  ## Usage
53
94
 
95
+ You can find here example of rails app with already configured knapsack.
96
+
97
+ https://github.com/KnapsackPro/rails-app-with-knapsack
98
+
54
99
  ### Step for RSpec
55
100
 
56
101
  Add at the beginning of your `spec_helper.rb`:
@@ -75,9 +120,22 @@ require 'knapsack'
75
120
  Knapsack::Adapters::CucumberAdapter.bind
76
121
  ```
77
122
 
123
+ ### Step for Minitest
124
+
125
+ Add at the beginning of your `test_helper.rb`:
126
+
127
+ ```ruby
128
+ require 'knapsack'
129
+
130
+ # CUSTOM_CONFIG_GOES_HERE
131
+
132
+ knapsack_adapter = Knapsack::Adapters::MinitestAdapter.bind
133
+ knapsack_adapter.set_test_helper_path(__FILE__)
134
+ ```
135
+
78
136
  ### Custom configuration
79
137
 
80
- You can change default Knapsack configuration for RSpec or Cucumber tests. Here are examples what you can do. Put below configuration instead of `CUSTOM_CONFIG_GOES_HERE`.
138
+ You can change default Knapsack configuration for RSpec, Cucumber or Minitest tests. Here are examples what you can do. Put below configuration instead of `CUSTOM_CONFIG_GOES_HERE`.
81
139
 
82
140
  ```ruby
83
141
  Knapsack.tracker.config({
@@ -112,9 +170,12 @@ Generate time execution report for your test files. Run below command on one of
112
170
  # Step for Cucumber
113
171
  $ KNAPSACK_GENERATE_REPORT=true bundle exec cucumber features
114
172
 
115
- Commit generated report `knapsack_rspec_report.json` or `knapsack_cucumber_report.json` into your repository.
173
+ # Step for Minitest
174
+ $ KNAPSACK_GENERATE_REPORT=true bundle exec rake test
116
175
 
117
- This report should be updated only after you add a lot of new slow tests or you change existing ones which causes a big time execution difference between CI nodes. Either way, you will get time offset warning at the end of the rspec/cucumber results which reminds you when it’s a good time to regenerate the knapsack report.
176
+ Commit generated report `knapsack_rspec_report.json`, `knapsack_cucumber_report.json` or `knapsack_minitest_report.json` into your repository.
177
+
178
+ This report should be updated only after you add a lot of new slow tests or you change existing ones which causes a big time execution difference between CI nodes. Either way, you will get time offset warning at the end of the rspec/cucumber/minitest results which reminds you when it’s a good time to regenerate the knapsack report.
118
179
 
119
180
  #### Adding or removing tests
120
181
 
@@ -132,6 +193,9 @@ On your CI server run this command for the first CI node. Update `CI_NODE_INDEX`
132
193
  # Step for Cucumber
133
194
  $ CI_NODE_TOTAL=2 CI_NODE_INDEX=0 bundle exec rake knapsack:cucumber
134
195
 
196
+ # Step for Minitest
197
+ $ CI_NODE_TOTAL=2 CI_NODE_INDEX=0 bundle exec rake knapsack:minitest
198
+
135
199
  You can add `KNAPSACK_TEST_FILE_PATTERN` if your tests are not in default directory. For instance:
136
200
 
137
201
  # Step for RSpec
@@ -140,6 +204,9 @@ You can add `KNAPSACK_TEST_FILE_PATTERN` if your tests are not in default direct
140
204
  # Step for Cucumber
141
205
  $ KNAPSACK_TEST_FILE_PATTERN="directory_with_features/**/*.feature" CI_NODE_TOTAL=2 CI_NODE_INDEX=0 bundle exec rake knapsack:cucumber
142
206
 
207
+ # Step for Minitest
208
+ $ KNAPSACK_TEST_FILE_PATTERN="directory_with_tests/**/*_test.rb" CI_NODE_TOTAL=2 CI_NODE_INDEX=0 bundle exec rake knapsack:minitest
209
+
143
210
  You can set `KNAPSACK_REPORT_PATH` if your knapsack report was saved in non default location. Example:
144
211
 
145
212
  # Step for RSpec
@@ -148,6 +215,9 @@ You can set `KNAPSACK_REPORT_PATH` if your knapsack report was saved in non defa
148
215
  # Step for Cucumber
149
216
  $ KNAPSACK_REPORT_PATH="knapsack_custom_report.json" CI_NODE_TOTAL=2 CI_NODE_INDEX=0 bundle exec rake knapsack:cucumber
150
217
 
218
+ # Step for Minitest
219
+ $ KNAPSACK_REPORT_PATH="knapsack_custom_report.json" CI_NODE_TOTAL=2 CI_NODE_INDEX=0 bundle exec rake knapsack:minitest
220
+
151
221
  ### Info about ENV variables
152
222
 
153
223
  `CI_NODE_TOTAL` - total number CI nodes you have.
@@ -172,6 +242,16 @@ Add arguments to knapsack cucumber task like this:
172
242
 
173
243
  $ bundle exec rake "knapsack:cucumber[--name feature]"
174
244
 
245
+ ### Passing arguments to minitest
246
+
247
+ Add arguments to knapsack minitest task like this:
248
+
249
+ $ bundle exec rake "knapsack:minitest[--arg_name value]"
250
+
251
+ For instance to run verbose tests:
252
+
253
+ $ bundle exec rake "knapsack:minitest[--verbose]"
254
+
175
255
  ### Info for CircleCI users
176
256
 
177
257
  If you are using circleci.com you can omit `CI_NODE_TOTAL` and `CI_NODE_INDEX`. Knapsack will use `CIRCLE_NODE_TOTAL` and `CIRCLE_NODE_INDEX` provided by CircleCI.
@@ -190,9 +270,12 @@ test:
190
270
 
191
271
  # Step for Cucumber
192
272
  - KNAPSACK_GENERATE_REPORT=true bundle exec cucumber features
273
+
274
+ # Step for Minitest
275
+ - KNAPSACK_GENERATE_REPORT=true bundle exec rake test
193
276
  ```
194
277
 
195
- After tests pass on your CircleCI machine your should copy knapsack json report which is rendered at the end of rspec/cucumber results. Save it into your repository as `knapsack_rspec_report.json` or `knapsack_cucumber_report.json` file and commit.
278
+ After tests pass on your CircleCI machine your should copy knapsack json report which is rendered at the end of rspec/cucumber/minitest results. Save it into your repository as `knapsack_rspec_report.json`, `knapsack_cucumber_report.json` or `knapsack_minitest_report.json` file and commit.
196
279
 
197
280
  #### Step 2
198
281
 
@@ -208,9 +291,13 @@ test:
208
291
  # Step for Cucumber
209
292
  - bundle exec rake knapsack:cucumber:
210
293
  parallel: true # Caution: there are 8 spaces indentation!
294
+
295
+ # Step for Minitest
296
+ - bundle exec rake knapsack:minitest:
297
+ parallel: true # Caution: there are 8 spaces indentation!
211
298
  ```
212
299
 
213
- Now everything should works. You will get warning at the end of rspec/cucumber results if time execution will take too much.
300
+ Now everything should works. You will get warning at the end of rspec/cucumber/minitest results if time execution will take too much.
214
301
 
215
302
  ### Info for Travis users
216
303
 
@@ -225,9 +312,12 @@ script:
225
312
 
226
313
  # Step for Cucumber
227
314
  - "KNAPSACK_GENERATE_REPORT=true bundle exec cucumber features"
315
+
316
+ # Step for Minitest
317
+ - "KNAPSACK_GENERATE_REPORT=true bundle exec rake test"
228
318
  ```
229
319
 
230
- After tests pass your should copy knapsack json report which is rendered at the end of rspec/cucumber results. Save it into your repository as `knapsack_rspec_report.json` or `knapsack_cucumber_report.json` file and commit.
320
+ After tests pass your should copy knapsack json report which is rendered at the end of rspec/cucumber/minitest results. Save it into your repository as `knapsack_rspec_report.json`, `knapsack_cucumber_report.json` or `knapsack_minitest_report.json` file and commit.
231
321
 
232
322
  #### Step 2
233
323
 
@@ -241,6 +331,9 @@ script:
241
331
  # Step for Cucumber
242
332
  - "bundle exec rake knapsack:cucumber"
243
333
 
334
+ # Step for Minitest
335
+ - "bundle exec rake knapsack:minitest"
336
+
244
337
  env:
245
338
  - CI_NODE_TOTAL=2 CI_NODE_INDEX=0
246
339
  - CI_NODE_TOTAL=2 CI_NODE_INDEX=1
@@ -256,6 +349,9 @@ script:
256
349
  # Step for Cucumber
257
350
  - "bundle exec rake knapsack:cucumber"
258
351
 
352
+ # Step for Minitest
353
+ - "bundle exec rake knapsack:minitest"
354
+
259
355
  env:
260
356
  global:
261
357
  - RAILS_ENV=test
@@ -285,23 +381,30 @@ For the first time run all tests at once with enabled report generator. Set up y
285
381
  # Step for Cucumber
286
382
  KNAPSACK_GENERATE_REPORT=true bundle exec cucumber features
287
383
 
288
- After tests pass your should copy knapsack json report which is rendered at the end of rspec/cucumber results. Save it into your repository as `knapsack_rspec_report.json` or `knapsack_cucumber_report.json` file and commit.
384
+ # Step for Minitest
385
+ KNAPSACK_GENERATE_REPORT=true bundle exec rake test
386
+
387
+ After tests pass your should copy knapsack json report which is rendered at the end of rspec/cucumber/test results. Save it into your repository as `knapsack_rspec_report.json`, `knapsack_cucumber_report.json` or `knapsack_minitest_report.json` file and commit.
289
388
 
290
389
  #### Step 2
291
390
 
292
- Knapsack supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_CURRENT_THREAD`. The only thing you need to do is set up knapsack rspec/cucumber command for as many threads as you need. Here is an example:
391
+ Knapsack supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_CURRENT_THREAD`. The only thing you need to do is set up knapsack rspec/cucumber/minitest command for as many threads as you need. Here is an example:
293
392
 
294
393
  # Thread 1
295
394
  ## Step for RSpec
296
395
  bundle exec rake knapsack:rspec
297
396
  ## Step for Cucumber
298
397
  bundle exec rake knapsack:cucumber
398
+ ## Step for Minitest
399
+ bundle exec rake knapsack:minitest
299
400
 
300
401
  # Thread 2
301
402
  ## Step for RSpec
302
403
  bundle exec rake knapsack:rspec
303
404
  ## Step for Cucumber
304
405
  bundle exec rake knapsack:cucumber
406
+ ## Step for Minitest
407
+ bundle exec rake knapsack:minitest
305
408
 
306
409
  Tests will be split across threads.
307
410
 
@@ -317,7 +420,10 @@ For the first time run all tests at once with enabled report generator. Run the
317
420
  # Step for Cucumber
318
421
  KNAPSACK_GENERATE_REPORT=true bundle exec cucumber features
319
422
 
320
- After tests pass your should copy knapsack json report which is rendered at the end of rspec/cucumber results. Save it into your repository as `knapsack_rspec_report.json` or `knapsack_cucumber_report.json` file and commit.
423
+ # Step for Minitest
424
+ KNAPSACK_GENERATE_REPORT=true bundle exec rake test
425
+
426
+ After tests pass your should copy knapsack json report which is rendered at the end of rspec/cucumber/minitest results. Save it into your repository as `knapsack_rspec_report.json`, `knapsack_cucumber_report.json` or `knapsack_minitest_report.json` file and commit.
321
427
 
322
428
  #### Step 2
323
429
 
@@ -329,6 +435,9 @@ Knapsack supports buildkite ENVs `BUILDKITE_PARALLEL_JOB_COUNT` and `BUILDKITE_P
329
435
  # Step for Cucumber
330
436
  bundle exec rake knapsack:cucumber
331
437
 
438
+ # Step for Minitest
439
+ bundle exec rake knapsack:minitest
440
+
332
441
  ## Gem tests
333
442
 
334
443
  ### Spec
data/Rakefile CHANGED
@@ -1,4 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
2
3
  require 'knapsack'
3
4
 
4
5
  Knapsack.load_tasks
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'test_examples'
9
+ t.pattern = 'test_examples/**/*_test.rb'
10
+ end
data/knapsack.gemspec CHANGED
@@ -18,10 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency 'rake', '>= 0'
22
+
21
23
  spec.add_development_dependency 'bundler', '~> 1.6'
22
- spec.add_development_dependency 'rake', '~> 0'
23
24
  spec.add_development_dependency 'rspec', '~> 3.0', '>= 2.0.0'
24
25
  spec.add_development_dependency 'cucumber', '>= 1.3'
26
+ spec.add_development_dependency 'minitest', '>= 5.0.0'
25
27
  spec.add_development_dependency 'timecop', '~> 0'
26
28
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 0'
27
29
  spec.add_development_dependency 'pry', '~> 0'
@@ -0,0 +1,5 @@
1
+ {
2
+ "test_examples/fast/unit_test.rb": 1.6192498207092285,
3
+ "test_examples/slow/slow_test.rb": 2.515178918838501,
4
+ "test_examples/fast/spec_test.rb": 0.0001010894775390625
5
+ }
data/lib/knapsack.rb CHANGED
@@ -15,6 +15,7 @@ require_relative 'knapsack/distributors/leftover_distributor'
15
15
  require_relative 'knapsack/adapters/base_adapter'
16
16
  require_relative 'knapsack/adapters/rspec_adapter'
17
17
  require_relative 'knapsack/adapters/cucumber_adapter'
18
+ require_relative 'knapsack/adapters/minitest_adapter'
18
19
 
19
20
  module Knapsack
20
21
  class << self
@@ -0,0 +1,60 @@
1
+ module Knapsack
2
+ module Adapters
3
+ class MinitestAdapter < BaseAdapter
4
+ TEST_DIR_PATTERN = 'test/**/*_test.rb'
5
+ REPORT_PATH = 'knapsack_minitest_report.json'
6
+ @@parent_of_test_dir = nil
7
+
8
+ # See how to write hooks and plugins
9
+ # https://github.com/seattlerb/minitest/blob/master/lib/minitest/test.rb
10
+ module BindTimeTrackerMinitestPlugin
11
+ def before_setup
12
+ super
13
+ Knapsack.tracker.test_path = MinitestAdapter.test_path(self)
14
+ Knapsack.tracker.start_timer
15
+ end
16
+
17
+ def after_teardown
18
+ Knapsack.tracker.stop_timer
19
+ super
20
+ end
21
+ end
22
+
23
+ def bind_time_tracker
24
+ ::Minitest::Test.send(:include, BindTimeTrackerMinitestPlugin)
25
+
26
+ ::Minitest.after_run do
27
+ Knapsack.logger.info(Presenter.global_time)
28
+ end
29
+ end
30
+
31
+ def bind_report_generator
32
+ Minitest.after_run do
33
+ Knapsack.report.save
34
+ Knapsack.logger.info(Presenter.report_details)
35
+ end
36
+ end
37
+
38
+ def bind_time_offset_warning
39
+ Minitest.after_run do
40
+ Knapsack.logger.warn(Presenter.time_offset_warning)
41
+ end
42
+ end
43
+
44
+ def set_test_helper_path(file_path)
45
+ test_dir_path = File.dirname(file_path)
46
+ @@parent_of_test_dir = File.expand_path('../', test_dir_path)
47
+ end
48
+
49
+ def self.test_path(obj)
50
+ test_method_name = obj.name
51
+ method_object = obj.method(test_method_name)
52
+ full_test_path = method_object.source_location.first
53
+ parent_of_test_dir_regexp = Regexp.new("^#{@@parent_of_test_dir}")
54
+ test_path = full_test_path.gsub(parent_of_test_dir_regexp, '.')
55
+ # test_path will look like ./test/dir/unit_test.rb
56
+ test_path
57
+ end
58
+ end
59
+ end
60
+ end
@@ -14,6 +14,10 @@ module Knapsack
14
14
  })
15
15
  end
16
16
 
17
+ def test_dir
18
+ test_file_pattern.split('/').first
19
+ end
20
+
17
21
  private
18
22
 
19
23
  def set_report_path
@@ -61,10 +61,14 @@ http://knapsack.launchrock.com}
61
61
 
62
62
  def pretty_seconds(seconds)
63
63
  sign = ''
64
+
64
65
  if seconds < 0
65
66
  seconds = seconds*-1
66
67
  sign = '-'
67
68
  end
69
+
70
+ return "#{sign}#{seconds}s" if seconds.abs < 1
71
+
68
72
  time = Time.at(seconds).gmtime.strftime('%Hh %Mm %Ss')
69
73
  time_without_zeros = time.gsub(/00(h|m|s)/, '').strip
70
74
  sign + time_without_zeros
@@ -25,7 +25,7 @@ module Knapsack
25
25
  report = File.read(report_path)
26
26
  JSON.parse(report)
27
27
  rescue Errno::ENOENT
28
- raise "Knapsack report file doesn't exist. Please generate report first!"
28
+ raise "Knapsack report file #{report_path} doesn't exist. Please generate report first!"
29
29
  end
30
30
 
31
31
  private
@@ -1,3 +1,3 @@
1
1
  module Knapsack
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'knapsack'
2
2
 
3
3
  namespace :knapsack do
4
- task :cucumber, [:cucumber_args] do |t, args|
4
+ task :cucumber, [:cucumber_args] do |_, args|
5
5
  allocator = Knapsack::AllocatorBuilder.new(Knapsack::Adapters::CucumberAdapter).allocator
6
6
 
7
7
  puts
@@ -0,0 +1,26 @@
1
+ require 'knapsack'
2
+ require 'rake/testtask'
3
+
4
+ namespace :knapsack do
5
+ Rake::TestTask.new(:minitest_run) do |t|
6
+ t.libs << ENV['KNAPSACK_MINITEST_TEST_DIR']
7
+ t.test_files = ENV['KNAPSACK_MINITEST_TEST_FILES'].to_s.split(' ')
8
+ end
9
+
10
+ task :minitest, [:minitest_args] do |_, args|
11
+ allocator = Knapsack::AllocatorBuilder.new(Knapsack::Adapters::MinitestAdapter).allocator
12
+
13
+ puts
14
+ puts 'Report tests:'
15
+ puts allocator.report_node_tests
16
+ puts
17
+ puts 'Leftover tests:'
18
+ puts allocator.leftover_node_tests
19
+ puts
20
+
21
+ cmd = %Q[TESTOPTS="#{args[:minitest_args]}" KNAPSACK_MINITEST_TEST_DIR="#{allocator.test_dir}" KNAPSACK_MINITEST_TEST_FILES="#{allocator.stringify_node_tests}" bundle exec rake knapsack:minitest_run]
22
+
23
+ system(cmd)
24
+ exit($?.exitstatus)
25
+ end
26
+ end
@@ -1,7 +1,7 @@
1
1
  require 'knapsack'
2
2
 
3
3
  namespace :knapsack do
4
- task :rspec, [:rspec_args] do |t, args|
4
+ task :rspec, [:rspec_args] do |_, args|
5
5
  allocator = Knapsack::AllocatorBuilder.new(Knapsack::Adapters::RspecAdapter).allocator
6
6
 
7
7
  puts
@@ -0,0 +1,125 @@
1
+ module FakeMinitest
2
+ class Test < ::Minitest::Test
3
+ include Knapsack::Adapters::MinitestAdapter::BindTimeTrackerMinitestPlugin
4
+ end
5
+ end
6
+
7
+ describe Knapsack::Adapters::MinitestAdapter do
8
+ describe 'BindTimeTrackerMinitestPlugin' do
9
+ let(:tracker) { instance_double(Knapsack::Tracker) }
10
+
11
+ subject { ::FakeMinitest::Test.new }
12
+
13
+ before do
14
+ allow(Knapsack).to receive(:tracker).and_return(tracker)
15
+ end
16
+
17
+ describe '#before_setup' do
18
+ let(:file) { 'test/models/user_test.rb' }
19
+
20
+ it do
21
+ expect(described_class).to receive(:test_path).with(subject).and_return(file)
22
+ expect(tracker).to receive(:test_path=).with(file)
23
+ expect(tracker).to receive(:start_timer)
24
+
25
+ subject.before_setup
26
+ end
27
+ end
28
+
29
+ describe '#after_teardown' do
30
+ it do
31
+ expect(tracker).to receive(:stop_timer)
32
+
33
+ subject.after_teardown
34
+ end
35
+ end
36
+ end
37
+
38
+ describe 'bind methods' do
39
+ let(:logger) { instance_double(Knapsack::Logger) }
40
+ let(:global_time) { 'Global time: 01m 05s' }
41
+
42
+ before do
43
+ expect(Knapsack).to receive(:logger).and_return(logger)
44
+ end
45
+
46
+ describe '#bind_time_tracker' do
47
+ it do
48
+ expect(::Minitest::Test).to receive(:send).with(:include, Knapsack::Adapters::MinitestAdapter::BindTimeTrackerMinitestPlugin)
49
+
50
+ expect(::Minitest).to receive(:after_run).and_yield
51
+ expect(Knapsack::Presenter).to receive(:global_time).and_return(global_time)
52
+ expect(logger).to receive(:info).with(global_time)
53
+
54
+ subject.bind_time_tracker
55
+ end
56
+ end
57
+
58
+ describe '#bind_report_generator' do
59
+ let(:report) { instance_double(Knapsack::Report) }
60
+ let(:report_details) { 'Report details' }
61
+
62
+ it do
63
+ expect(::Minitest).to receive(:after_run).and_yield
64
+
65
+ expect(Knapsack).to receive(:report).and_return(report)
66
+ expect(report).to receive(:save)
67
+
68
+ expect(Knapsack::Presenter).to receive(:report_details).and_return(report_details)
69
+ expect(logger).to receive(:info).with(report_details)
70
+
71
+ subject.bind_report_generator
72
+ end
73
+ end
74
+
75
+ describe '#bind_time_offset_warning' do
76
+ let(:time_offset_warning) { 'Time offset warning' }
77
+
78
+ it do
79
+ expect(::Minitest).to receive(:after_run).and_yield
80
+
81
+ expect(Knapsack::Presenter).to receive(:time_offset_warning).and_return(time_offset_warning)
82
+ expect(logger).to receive(:warn).with(time_offset_warning)
83
+
84
+ subject.bind_time_offset_warning
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#set_test_helper_path' do
90
+ let(:adapter) { described_class.new }
91
+ let(:test_helper_path) { '/code/project/test/test_helper.rb' }
92
+
93
+ subject { adapter.set_test_helper_path(test_helper_path) }
94
+
95
+ after do
96
+ expect(described_class.class_variable_get(:@@parent_of_test_dir)).to eq '/code/project'
97
+ end
98
+
99
+ it { should eql '/code/project' }
100
+ end
101
+
102
+ describe '.test_path' do
103
+ class FakeUserTest
104
+ def test_user_age; end
105
+
106
+ # method provided by Minitest
107
+ # it returns test method name
108
+ def name
109
+ :test_user_age
110
+ end
111
+ end
112
+
113
+ let(:obj) { FakeUserTest.new }
114
+
115
+ subject { described_class.test_path(obj) }
116
+
117
+ before do
118
+ parent_of_test_dir = File.expand_path('../../../', File.dirname(__FILE__))
119
+ parent_of_test_dir_regexp = Regexp.new("^#{parent_of_test_dir}")
120
+ described_class.class_variable_set(:@@parent_of_test_dir, parent_of_test_dir_regexp)
121
+ end
122
+
123
+ it { should eq './spec/knapsack/adapters/minitest_adapter_spec.rb' }
124
+ end
125
+ end
@@ -85,4 +85,24 @@ describe Knapsack::AllocatorBuilder do
85
85
  it_behaves_like 'allocator builder'
86
86
  end
87
87
  end
88
+
89
+ describe '#test_dir' do
90
+ let(:adapter_class) { Knapsack::Adapters::RspecAdapter }
91
+
92
+ subject { allocator_builder.test_dir }
93
+
94
+ before do
95
+ expect(Knapsack::Config::Env).to receive(:test_file_pattern).and_return(env_test_file_pattern)
96
+ end
97
+
98
+ context 'when ENV test_file_pattern has value' do
99
+ let(:env_test_file_pattern) { 'custom_spec/**/*_spec.rb' }
100
+
101
+ it { should eq 'custom_spec' }
102
+ end
103
+
104
+ context 'when ENV test_file_pattern has no value' do
105
+ it { should eq 'spec' }
106
+ end
107
+ end
88
108
  end
@@ -84,6 +84,16 @@ describe Knapsack::Presenter do
84
84
  describe '.pretty_seconds' do
85
85
  subject { described_class.pretty_seconds(seconds) }
86
86
 
87
+ context 'when less then one second' do
88
+ let(:seconds) { 0.987 }
89
+ it { should eql '0.987s' }
90
+ end
91
+
92
+ context 'when one second' do
93
+ let(:seconds) { 1 }
94
+ it { should eql '01s' }
95
+ end
96
+
87
97
  context 'when only seconds' do
88
98
  let(:seconds) { 5 }
89
99
  it { should eql '05s' }
@@ -62,7 +62,7 @@ describe Knapsack::Report do
62
62
  it do
63
63
  expect {
64
64
  subject
65
- }.to raise_error("Knapsack report file doesn't exist. Please generate report first!")
65
+ }.to raise_error("Knapsack report file #{report_path} doesn't exist. Please generate report first!")
66
66
  end
67
67
  end
68
68
  end
@@ -2,10 +2,12 @@ describe Knapsack::TaskLoader do
2
2
  describe '#load_tasks' do
3
3
  let(:rspec_rake_task_path) { "#{Knapsack.root}/lib/tasks/knapsack_rspec.rake" }
4
4
  let(:cucumber_rake_task_path) { "#{Knapsack.root}/lib/tasks/knapsack_cucumber.rake" }
5
+ let(:minitest_rake_task_path) { "#{Knapsack.root}/lib/tasks/knapsack_minitest.rake" }
5
6
 
6
7
  it do
7
8
  expect(subject).to receive(:import).with(rspec_rake_task_path)
8
9
  expect(subject).to receive(:import).with(cucumber_rake_task_path)
10
+ expect(subject).to receive(:import).with(minitest_rake_task_path)
9
11
  subject.load_tasks
10
12
  end
11
13
  end
@@ -0,0 +1,12 @@
1
+ # https://github.com/seattlerb/minitest/blob/master/lib/minitest/test.rb
2
+ module Minitest
3
+ class Test
4
+ def before_setup; end
5
+ def after_teardown; end
6
+ end
7
+
8
+ # https://github.com/seattlerb/minitest/blob/master/lib/minitest.rb
9
+ def self.after_run(&block)
10
+ block.call
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class FakeCalculator
4
+ def add(x, y)
5
+ x + y
6
+ end
7
+
8
+ def mal(x, y)
9
+ x * y
10
+ end
11
+ end
12
+
13
+ describe FakeCalculator do
14
+ before do
15
+ @calc = FakeCalculator.new
16
+ end
17
+
18
+ it '#add' do
19
+ @calc.add(2, 3).must_equal 5
20
+ end
21
+
22
+ it '#mal' do
23
+ @calc.mal(2, 3).must_equal 6
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class UnitTest < Minitest::Test
4
+ def setup
5
+ sleep 0.1
6
+ end
7
+
8
+ def test_mal
9
+ sleep 0.1
10
+ assert_equal 4, 2 * 2
11
+ end
12
+
13
+ def test_no_way
14
+ sleep 0.2
15
+ refute_match(/^no/i, 'yes')
16
+ end
17
+
18
+ def test_that_will_be_skipped
19
+ sleep 1
20
+ skip 'test this later'
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class SlowTest < Minitest::Test
4
+ def setup
5
+ sleep 0.5
6
+ end
7
+
8
+ def test_a
9
+ sleep 0.5
10
+ end
11
+
12
+ def test_b
13
+ sleep 1.0
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ require 'minitest/autorun'
2
+
3
+ require 'knapsack'
4
+
5
+ Knapsack.tracker.config({
6
+ enable_time_offset_warning: true,
7
+ time_offset_in_seconds: 3
8
+ })
9
+ Knapsack.report.config({
10
+ report_path: 'knapsack_minitest_report.json'
11
+ })
12
+
13
+ if ENV['CUSTOM_LOGGER']
14
+ require 'logger'
15
+ Knapsack.logger = Logger.new(STDOUT)
16
+ Knapsack.logger.level = Logger::INFO
17
+ end
18
+
19
+ knapsack_adapter = Knapsack::Adapters::MinitestAdapter.bind
20
+ knapsack_adapter.set_test_helper_path(__FILE__)
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-30 00:00:00.000000000 Z
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :development
19
+ version: '0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.6'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '1.3'
75
+ - !ruby/object:Gem::Dependency
76
+ name: minitest
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 5.0.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 5.0.0
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: timecop
77
91
  requirement: !ruby/object:Gem::Requirement
@@ -132,7 +146,6 @@ files:
132
146
  - LICENSE.txt
133
147
  - README.md
134
148
  - Rakefile
135
- - TODO.md
136
149
  - bin/print_header.sh
137
150
  - docs/images/logos/knapsack-@2.png
138
151
  - docs/images/logos/knapsack-big.png
@@ -143,10 +156,12 @@ files:
143
156
  - docs/images/with_knapsack.png
144
157
  - docs/images/without_knapsack.png
145
158
  - knapsack.gemspec
159
+ - knapsack_minitest_report.json
146
160
  - knapsack_rspec_report.json
147
161
  - lib/knapsack.rb
148
162
  - lib/knapsack/adapters/base_adapter.rb
149
163
  - lib/knapsack/adapters/cucumber_adapter.rb
164
+ - lib/knapsack/adapters/minitest_adapter.rb
150
165
  - lib/knapsack/adapters/rspec_adapter.rb
151
166
  - lib/knapsack/allocator.rb
152
167
  - lib/knapsack/allocator_builder.rb
@@ -162,9 +177,11 @@ files:
162
177
  - lib/knapsack/tracker.rb
163
178
  - lib/knapsack/version.rb
164
179
  - lib/tasks/knapsack_cucumber.rake
180
+ - lib/tasks/knapsack_minitest.rake
165
181
  - lib/tasks/knapsack_rspec.rake
166
182
  - spec/knapsack/adapters/base_adapter_spec.rb
167
183
  - spec/knapsack/adapters/cucumber_adapter_spec.rb
184
+ - spec/knapsack/adapters/minitest_adapter_spec.rb
168
185
  - spec/knapsack/adapters/rspec_adapter_spec.rb
169
186
  - spec/knapsack/allocator_builder_spec.rb
170
187
  - spec/knapsack/allocator_spec.rb
@@ -181,6 +198,7 @@ files:
181
198
  - spec/knapsack_spec.rb
182
199
  - spec/spec_helper.rb
183
200
  - spec/support/mocks/cucumber.rb
201
+ - spec/support/mocks/minitest.rb
184
202
  - spec/support/shared_examples/adapter.rb
185
203
  - spec_examples/fast/1_spec.rb
186
204
  - spec_examples/fast/2_spec.rb
@@ -196,6 +214,10 @@ files:
196
214
  - spec_examples/slow/c_spec.rb
197
215
  - spec_examples/spec_helper.rb
198
216
  - spec_examples/support/shared_examples/common_example.rb
217
+ - test_examples/fast/spec_test.rb
218
+ - test_examples/fast/unit_test.rb
219
+ - test_examples/slow/slow_test.rb
220
+ - test_examples/test_helper.rb
199
221
  homepage: https://github.com/ArturT/knapsack
200
222
  licenses:
201
223
  - MIT
@@ -216,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
238
  version: '0'
217
239
  requirements: []
218
240
  rubyforge_project:
219
- rubygems_version: 2.4.2
241
+ rubygems_version: 2.4.6
220
242
  signing_key:
221
243
  specification_version: 4
222
244
  summary: Knapsack splits tests across CI nodes and makes sure that tests will run
@@ -224,6 +246,7 @@ summary: Knapsack splits tests across CI nodes and makes sure that tests will ru
224
246
  test_files:
225
247
  - spec/knapsack/adapters/base_adapter_spec.rb
226
248
  - spec/knapsack/adapters/cucumber_adapter_spec.rb
249
+ - spec/knapsack/adapters/minitest_adapter_spec.rb
227
250
  - spec/knapsack/adapters/rspec_adapter_spec.rb
228
251
  - spec/knapsack/allocator_builder_spec.rb
229
252
  - spec/knapsack/allocator_spec.rb
@@ -240,4 +263,5 @@ test_files:
240
263
  - spec/knapsack_spec.rb
241
264
  - spec/spec_helper.rb
242
265
  - spec/support/mocks/cucumber.rb
266
+ - spec/support/mocks/minitest.rb
243
267
  - spec/support/shared_examples/adapter.rb
data/TODO.md DELETED
@@ -1,4 +0,0 @@
1
- # TODO
2
-
3
- * Add other adapters and rake tasks than RSpec and Cucumber.
4
- * Add support for ENV CI node total and CI node index other than CircleCI.