knapsack_pro 0.50.1 → 0.51.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: f32dbba867743ab3b02ad56fe56507c7bdef81df
4
- data.tar.gz: 3e08b6ad44aac4d400e92caef47897c2163b5998
3
+ metadata.gz: 10e2d8e67cd45d4f4624e1c9630b27e5d83b6967
4
+ data.tar.gz: 160d472acb1cab42aa1870d62ee84dd1c897e216
5
5
  SHA512:
6
- metadata.gz: 2339de8c7ef40f0ee30c5c57582641d599b7bcff66e639075e8feaebdd9a7ec7d231db3191d1b4f485f46a77aa29736fe2cb67612976c28455fbb82853c81be8
7
- data.tar.gz: 60aabaa69b57233e94f76034c9fb4484ddcab86cd70ccc90ddbe80ca78303df65ee5a4cec1fc4bddf84eefc19f7d7d9c5418ffbb5ca3b54a36b20f78cba99ebf
6
+ metadata.gz: 6aa5e6a9480e6c8e96669ddfa20bce9b62251ecb8aafb95d5ef25aec88a34ca138e922f5b8e8452e8a9577cd645be19c5a016efafe26a94319a7c6763dc57557
7
+ data.tar.gz: 96d936aacfb332ebe49b0e669fcd2b55ded28c9e563a82f50da74a68892820be58091d53595e6b77e0d1a0ce314268613f7cf3ff7b6ac121db332ebd3cc295ca
@@ -2,6 +2,14 @@
2
2
 
3
3
  * TODO
4
4
 
5
+ ### 0.51.0
6
+
7
+ * Add support for test-unit test runner.
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/53
10
+
11
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.50.1...v0.51.0
12
+
5
13
  ### 0.50.1
6
14
 
7
15
  * Update RSpec timing adapter to be more resilient.
data/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
  [![Code Climate](https://codeclimate.com/github/KnapsackPro/knapsack_pro-ruby/badges/gpa.svg)](https://codeclimate.com/github/KnapsackPro/knapsack_pro-ruby)
6
6
  [![Test Coverage](https://codeclimate.com/github/KnapsackPro/knapsack-pro-ruby/badges/coverage.svg)](https://codeclimate.com/github/KnapsackPro/knapsack-pro-ruby/coverage)
7
7
 
8
+ Follow us on [Twitter @KnapsackPro](https://twitter.com/KnapsackPro) and give Like on [Facebook KnapsackPro](https://www.facebook.com/KnapsackPro)
9
+
8
10
  Knapsack Pro gem splits tests across CI nodes and makes sure that tests will run comparable time on each node. It uses [KnapsackPro.com API](http://docs.knapsackpro.com). You can learn more at [https://knapsackpro.com](https://knapsackpro.com?utm_source=github&utm_medium=readme&utm_campaign=knapsack_pro-ruby_gem&utm_content=learn_more)
9
11
 
10
12
  The knapsack_pro gem supports:
@@ -12,6 +14,7 @@ The knapsack_pro gem supports:
12
14
  * [RSpec](http://rspec.info)
13
15
  * [Cucumber](https://cucumber.io)
14
16
  * [Minitest](http://docs.seattlerb.org/minitest/)
17
+ * [test-unit](https://github.com/test-unit/test-unit)
15
18
  * [Spinach](https://github.com/codegram/spinach)
16
19
  * [Turnip](https://github.com/jnicklas/turnip)
17
20
 
@@ -60,6 +63,7 @@ The knapsack_pro has also [queue mode](#queue-mode) to get an optimal test suite
60
63
  - [Step for RSpec](#step-for-rspec)
61
64
  - [Step for Cucumber](#step-for-cucumber)
62
65
  - [Step for Minitest](#step-for-minitest)
66
+ - [Step for test-unit](#step-for-test-unit)
63
67
  - [Step for Spinach](#step-for-spinach)
64
68
  - [Custom configuration](#custom-configuration)
65
69
  - [Setup your CI server (How to set up 2 of 3)](#setup-your-ci-server-how-to-set-up-2-of-3)
@@ -84,6 +88,7 @@ The knapsack_pro has also [queue mode](#queue-mode) to get an optimal test suite
84
88
  - [Passing arguments to rspec](#passing-arguments-to-rspec)
85
89
  - [Passing arguments to cucumber](#passing-arguments-to-cucumber)
86
90
  - [Passing arguments to minitest](#passing-arguments-to-minitest)
91
+ - [Passing arguments to test-unit](#passing-arguments-to-test-unit)
87
92
  - [Passing arguments to spinach](#passing-arguments-to-spinach)
88
93
  - [Knapsack Pro binary](#knapsack-pro-binary)
89
94
  - [Test file names encryption](#test-file-names-encryption)
@@ -93,6 +98,7 @@ The knapsack_pro has also [queue mode](#queue-mode) to get an optimal test suite
93
98
  - [How to debug branch names?](#how-to-debug-branch-names)
94
99
  - [Supported CI providers](#supported-ci-providers)
95
100
  - [Info for CircleCI users](#info-for-circleci-users)
101
+ - [CircleCI and knapsack_pro Queue Mode](#circleci-and-knapsack_pro-queue-mode)
96
102
  - [Info for Travis users](#info-for-travis-users)
97
103
  - [Info for semaphoreapp.com users](#info-for-semaphoreappcom-users)
98
104
  - [Info for buildkite.com users](#info-for-buildkitecom-users)
@@ -105,6 +111,7 @@ The knapsack_pro has also [queue mode](#queue-mode) to get an optimal test suite
105
111
  - [Why I see API error commit_hash parameter is required?](#why-i-see-api-error-commit_hash-parameter-is-required)
106
112
  - [Why I see `LoadError: cannot load such file -- spec_helper`?](#why-i-see-loaderror-cannot-load-such-file----spec_helper)
107
113
  - [Queue Mode problems](#queue-mode-problems)
114
+ - [Why when I use Queue Mode for RSpec then my tests fail?](#why-when-i-use-queue-mode-for-rspec-then-my-tests-fail)
108
115
  - [Why I don't see collected time execution data for my build in user dashboard?](#why-i-dont-see-collected-time-execution-data-for-my-build-in-user-dashboard)
109
116
  - [Why when I use Queue Mode for RSpec and test fails then I see multiple times info about failed test in RSpec result?](#why-when-i-use-queue-mode-for-rspec-and-test-fails-then-i-see-multiple-times-info-about-failed-test-in-rspec-result)
110
117
  - [Why when I use Queue Mode for RSpec then I see multiple times the same pending tests?](#why-when-i-use-queue-mode-for-rspec-then-i-see-multiple-times-the-same-pending-tests)
@@ -256,6 +263,19 @@ knapsack_pro_adapter = KnapsackPro::Adapters::MinitestAdapter.bind
256
263
  knapsack_pro_adapter.set_test_helper_path(__FILE__)
257
264
  ```
258
265
 
266
+ #### Step for test-unit
267
+
268
+ Add at the beginning of your `test_helper.rb`:
269
+
270
+ ```ruby
271
+ require 'knapsack_pro'
272
+
273
+ # CUSTOM_CONFIG_GOES_HERE
274
+
275
+ knapsack_pro_adapter = KnapsackPro::Adapters::TestUnitAdapter.bind
276
+ knapsack_pro_adapter.set_test_helper_path(__FILE__)
277
+ ```
278
+
259
279
  #### Step for Spinach
260
280
 
261
281
  Create file `features/support/knapsack_pro.rb` and add there:
@@ -270,7 +290,7 @@ KnapsackPro::Adapters::SpinachAdapter.bind
270
290
 
271
291
  #### Custom configuration
272
292
 
273
- You can change the default Knapsack Pro configuration for RSpec, Cucumber, Minitest or Spinach tests. Here are examples what you can do. Put the configuration below in place of `CUSTOM_CONFIG_GOES_HERE` (in the configuration samples above).
293
+ You can change the default Knapsack Pro configuration for RSpec, Cucumber, Minitest, test-unit or Spinach tests. Here are examples what you can do. Put the configuration below in place of `CUSTOM_CONFIG_GOES_HERE` (in the configuration samples above).
274
294
 
275
295
  ```ruby
276
296
  # you can use your own logger
@@ -290,7 +310,8 @@ Set one or more tokens depending on how many test suites you run on CI server.
290
310
  * `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` - as value set token for rspec test suite. Token can be generated when you sign in to [knapsackpro.com](http://www.knapsackpro.com).
291
311
  * `KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER` - token for cucumber test suite.
292
312
  * `KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST` - token for minitest test suite.
293
- * `KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH` - token for minitest test suite.
313
+ * `KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT` - token for test-unit test suite.
314
+ * `KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH` - token for spinach test suite.
294
315
 
295
316
  __Tip:__ In case you have for instance multiple rspec test suites then prepend each of knapsack_pro command which executes tests with `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` variable.
296
317
 
@@ -307,6 +328,9 @@ On your CI server run this command for the first CI node. Update `KNAPSACK_PRO_C
307
328
  # Step for Minitest
308
329
  $ KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:minitest
309
330
 
331
+ # Step for test-unit
332
+ $ KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:test_unit
333
+
310
334
  # Step for Spinach
311
335
  $ KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:spinach
312
336
 
@@ -321,6 +345,9 @@ You can add `KNAPSACK_PRO_TEST_FILE_PATTERN` if your tests are not in default di
321
345
  # Step for Minitest
322
346
  $ KNAPSACK_PRO_TEST_FILE_PATTERN="directory_with_tests/**{,/*/**}/*_test.rb" KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:minitest
323
347
 
348
+ # Step for test-unit
349
+ $ KNAPSACK_PRO_TEST_FILE_PATTERN="directory_with_tests/**{,/*/**}/*_test.rb" KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:test_unit
350
+
324
351
  # Step for Spinach
325
352
  $ KNAPSACK_PRO_TEST_FILE_PATTERN="directory_with_features/**{,/*/**}/*.feature" KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:spinach
326
353
 
@@ -529,6 +556,16 @@ For instance to run verbose tests:
529
556
 
530
557
  $ bundle exec rake "knapsack_pro:minitest[--verbose]"
531
558
 
559
+ #### Passing arguments to test-unit
560
+
561
+ Add arguments to knapsack_pro test-unit task like this:
562
+
563
+ $ bundle exec rake "knapsack_pro:test_unit[--arg_name value]"
564
+
565
+ For instance to run verbose tests:
566
+
567
+ $ bundle exec rake "knapsack_pro:test_unit[--verbose]"
568
+
532
569
  #### Passing arguments to spinach
533
570
 
534
571
  Add arguments to knapsack_pro spinach task like this:
@@ -543,6 +580,7 @@ You can install knapsack_pro globally and use binary. For instance:
543
580
  $ knapsack_pro queue:rspec "--tag custom_tag_name --profile"
544
581
  $ knapsack_pro cucumber "--name feature"
545
582
  $ knapsack_pro minitest "--verbose --pride"
583
+ $ knapsack_pro test_unit "--verbose"
546
584
  $ knapsack_pro spinach "--arg_name value"
547
585
 
548
586
  This is optional way of using knapsack_pro when you don't want to add it to `Gemfile`.
@@ -576,7 +614,7 @@ If you need to check what is the encryption hash for particular test file you ca
576
614
 
577
615
  $ KNAPSACK_PRO_SALT=xxx bundle exec rake knapsack_pro:encrypted_test_file_names[rspec]
578
616
 
579
- You can pass the name of test runner like `rspec`, `minitest`, `cucumber`, `spinach` as argument to rake task.
617
+ You can pass the name of test runner like `rspec`, `minitest`, `test_unit`, `cucumber`, `spinach` as argument to rake task.
580
618
 
581
619
  #### How to enable branch names encryption?
582
620
 
@@ -617,6 +655,7 @@ machine:
617
655
  # KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: rspec-token
618
656
  # KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER: cucumber-token
619
657
  # KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST: minitest-token
658
+ # KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT: test-unit-token
620
659
  # KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH: spinach-token
621
660
  test:
622
661
  override:
@@ -632,6 +671,10 @@ test:
632
671
  - bundle exec rake knapsack_pro:minitest:
633
672
  parallel: true # Caution: there are 8 spaces indentation!
634
673
 
674
+ # Step for test-unit
675
+ - bundle exec rake knapsack_pro:test_unit:
676
+ parallel: true # Caution: there are 8 spaces indentation!
677
+
635
678
  # Step for Spinach
636
679
  - bundle exec rake knapsack_pro:spinach:
637
680
  parallel: true # Caution: there are 8 spaces indentation!
@@ -658,6 +701,36 @@ Here is another example for CircleCI 2.0 platform.
658
701
 
659
702
  Please remember to add additional containers for your project in CircleCI settings.
660
703
 
704
+ ##### CircleCI and knapsack_pro Queue Mode
705
+
706
+ If you use knapack_pro Queue Mode with CircleCI you may want to [collect metadata](https://circleci.com/docs/1.0/test-metadata/#metadata-collection-in-custom-test-steps) like junit xml report about your RSpec test suite.
707
+
708
+ Here you can read how to configure [junit formatter](#how-to-use-junit-formatter-with-knapsack_pro-queue-mode). Step for CircleCI is to copy the xml report to `$CIRCLE_TEST_REPORTS` directory. Below is full config for your `spec_helper.rb`:
709
+
710
+ ```ruby
711
+ # spec_helper.rb or rails_helper.rb
712
+
713
+ # TODO This must be the same path as value for rspec --out argument
714
+ TMP_RSPEC_XML_REPORT = 'tmp/rspec.xml'
715
+ # move results to FINAL_RSPEC_XML_REPORT so the results won't accumulate with duplicated xml tags in TMP_RSPEC_XML_REPORT
716
+ FINAL_RSPEC_XML_REPORT = 'tmp/rspec_final_results.xml'
717
+
718
+ KnapsackPro::Hooks::Queue.after_subset_queue do |queue_id, subset_queue_id|
719
+ if File.exist?(TMP_RSPEC_XML_REPORT)
720
+ FileUtils.mv(TMP_RSPEC_XML_REPORT, FINAL_RSPEC_XML_REPORT)
721
+ end
722
+ end
723
+
724
+ # Here is additional configuration to ensure the xml report will be visible by CircleCI
725
+ KnapsackPro::Hooks::Queue.after_queue do |queue_id|
726
+ # Metadata collection
727
+ # https://circleci.com/docs/1.0/test-metadata/#metadata-collection-in-custom-test-steps
728
+ if File.exist?(FINAL_RSPEC_XML_REPORT) && ENV['CIRCLE_TEST_REPORTS']
729
+ FileUtils.cp(FINAL_RSPEC_XML_REPORT, "#{ENV['CIRCLE_TEST_REPORTS']}/rspec.xml")
730
+ end
731
+ end
732
+ ```
733
+
661
734
  #### Info for Travis users
662
735
 
663
736
  You can parallelize your builds across virtual machines with [travis matrix feature](http://docs.travis-ci.com/user/speeding-up-the-build/#Parallelizing-your-builds-across-virtual-machines). Edit `.travis.yml`
@@ -673,6 +746,9 @@ script:
673
746
  # Step for Minitest
674
747
  - "bundle exec rake knapsack_pro:minitest"
675
748
 
749
+ # Step for test-unit
750
+ - "bundle exec rake knapsack_pro:test_unit"
751
+
676
752
  # Step for Spinach
677
753
  - "bundle exec rake knapsack_pro:spinach"
678
754
 
@@ -682,6 +758,7 @@ env:
682
758
  - KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=rspec-token
683
759
  - KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=cucumber-token
684
760
  - KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=minitest-token
761
+ - KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT=test-unit-token
685
762
  - KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH=spinach-token
686
763
 
687
764
  - KNAPSACK_PRO_CI_NODE_TOTAL=2
@@ -692,14 +769,14 @@ env:
692
769
 
693
770
  Such configuration will generate matrix with 2 following ENV rows:
694
771
 
695
- KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=rspec-token KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=cucumber-token KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=minitest-token KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH=spinach-token
696
- KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=1 KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=rspec-token KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=cucumber-token KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=minitest-token KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH=spinach-token
772
+ KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=rspec-token KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=cucumber-token KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=minitest-token KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT=test-unit-token KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH=spinach-token
773
+ KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=1 KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=rspec-token KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=cucumber-token KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=minitest-token KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT=test-unit-token KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH=spinach-token
697
774
 
698
775
  More info about global and matrix ENV configuration in [travis docs](https://docs.travis-ci.com/user/customizing-the-build/#Build-Matrix).
699
776
 
700
777
  #### Info for semaphoreapp.com users
701
778
 
702
- Knapsack Pro supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_CURRENT_THREAD`. The only thing you need to do is set up knapsack_pro rspec/cucumber/minitest command for as many threads as you need. Here is an example:
779
+ Knapsack Pro supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_CURRENT_THREAD`. The only thing you need to do is set up knapsack_pro rspec/cucumber/minitest/test_unit command for as many threads as you need. Here is an example:
703
780
 
704
781
  # Thread 1
705
782
  ## Step for RSpec
@@ -708,6 +785,8 @@ Knapsack Pro supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_
708
785
  bundle exec rake knapsack_pro:cucumber
709
786
  ## Step for Minitest
710
787
  bundle exec rake knapsack_pro:minitest
788
+ ## Step for test-unit
789
+ bundle exec rake knapsack_pro:test_unit
711
790
  ## Step for Spinach
712
791
  bundle exec rake knapsack_pro:spinach
713
792
 
@@ -718,6 +797,8 @@ Knapsack Pro supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_
718
797
  bundle exec rake knapsack_pro:cucumber
719
798
  ## Step for Minitest
720
799
  bundle exec rake knapsack_pro:minitest
800
+ ## Step for test-unit
801
+ bundle exec rake knapsack_pro:test_unit
721
802
  ## Step for Spinach
722
803
  bundle exec rake knapsack_pro:spinach
723
804
 
@@ -738,6 +819,9 @@ Knapsack Pro supports buildkite ENVs `BUILDKITE_PARALLEL_JOB_COUNT` and `BUILDKI
738
819
  # Step for Minitest
739
820
  bundle exec rake knapsack_pro:minitest
740
821
 
822
+ # Step for test-unit
823
+ bundle exec rake knapsack_pro:test_unit
824
+
741
825
  # Step for Spinach
742
826
  bundle exec rake knapsack_pro:spinach
743
827
 
@@ -829,6 +913,9 @@ Knapsack Pro supports snap-ci.com ENVs `SNAP_WORKER_TOTAL` and `SNAP_WORKER_INDE
829
913
  # Step for Minitest
830
914
  bundle exec rake knapsack_pro:minitest
831
915
 
916
+ # Step for test-unit
917
+ bundle exec rake knapsack_pro:test_unit
918
+
832
919
  # Step for Spinach
833
920
  bundle exec rake knapsack_pro:spinach
834
921
 
@@ -921,6 +1008,16 @@ then problem might be related to the fact you specified complex `KNAPSACK_PRO_TE
921
1008
 
922
1009
  #### Queue Mode problems
923
1010
 
1011
+ ##### Why when I use Queue Mode for RSpec then my tests fail?
1012
+
1013
+ knapsack_pro Queue Mode uses `RSpec::Core::Runner` feature that allows [running specs multiple times with different runner options in the same process](https://relishapp.com/rspec/rspec-core/docs/running-specs-multiple-times-with-different-runner-options-in-the-same-process).
1014
+ Thanks to that we can run subset of test suite pulled from Knapsack Pro API work queue. This allows dynamic allocation of your tests across CI nodes without reloading whole Ruby/Rails application for each run of test suite subset .
1015
+
1016
+ If you have custom things that are not common in how typical RSpec spec looks like then the RSpec feature won't be able to handle it between test suite subset runs.
1017
+ In that case you need to resolve failed tests in a way that allows RSpec to run the tests. Feel free to [ask me for help](https://knapsackpro.com/contact).
1018
+
1019
+ You can learn more about [recent RSpec team changes](https://github.com/KnapsackPro/knapsack_pro-ruby/pull/42) that was backported into knapsack_pro.
1020
+
924
1021
  ##### Why I don't see collected time execution data for my build in user dashboard?
925
1022
 
926
1023
  If you go to [user dashboard](https://knapsackpro.com/dashboard) and open `Build metrics` for your API token and you open build for your last git commit you should see there info about collected time execution data from all CI nodes. If you don't see collected time execution data for CI nodes then please ensure:
@@ -986,7 +1083,7 @@ For instance to run subset of tests for the first CI node with specified seed yo
986
1083
  KNAPSACK_PRO_CI_NODE_INDEX=0 \
987
1084
  bundle exec rake "knapsack_pro:rspec[--seed 123]"
988
1085
 
989
- Above example is for RSpec. You can use respectively rake task name and token environment variable when you want to run tests for minitest, cucumber or spinach.
1086
+ Above example is for RSpec. You can use respectively rake task name and token environment variable when you want to run tests for minitest, test_unit, cucumber or spinach.
990
1087
  It should work when all CI nodes finished work and sent time execution data to Knapsack Pro API.
991
1088
  You can visit [user dashboard](https://knapsackpro.com/dashboard) to preview particular CI build and ensure time execution data were collected from all CI nodes.
992
1089
  If at least one CI node has not sent time execution data to the Knapsack Pro API then you should check below solution.
@@ -1081,7 +1178,7 @@ A lot of small test files will give you better test suite split results.
1081
1178
 
1082
1179
  Another way is to use tags to mark subset of tests in particular test file and then split tests based on tags.
1083
1180
 
1084
- This example is for knapack_pro Regular Mode. I don't recommend to user this approach with Queue Mode.
1181
+ This example is for knapack_pro Regular Mode. You can also use knapack_pro Queue Mode with tags.
1085
1182
 
1086
1183
  Here is example of test file with specified tags for describe groups:
1087
1184
 
@@ -1103,7 +1200,7 @@ describe 'Feature' do
1103
1200
  end
1104
1201
  ```
1105
1202
 
1106
- You need to create multiple API tokens for different tags. In this example we need 3 different API tokens.
1203
+ You need to create API token per each tag. In this example we need 3 different API tokens.
1107
1204
 
1108
1205
  You need to run below commands for each CI node.
1109
1206
 
@@ -1168,12 +1265,16 @@ You can use junit formatter for rspec thanks to gem [rspec_junit_formatter](http
1168
1265
  The xml report will contain all tests executed across intermediate test subset runs based on work queue. You need to add after subset queue hook to rename `rspec.xml` to `rspec_final_results.xml` thanks to that the final results file will contain only single xml tag with all tests executed on the CI node. This is related to the way how queue mode works. Detailed explanation is in the [issue](https://github.com/KnapsackPro/knapsack_pro-ruby/issues/40).
1169
1266
 
1170
1267
  # spec_helper.rb or rails_helper.rb
1268
+
1269
+ # TODO This must be the same path as value for rspec --out argument
1270
+ TMP_RSPEC_XML_REPORT = 'tmp/rspec.xml'
1271
+ # move results to FINAL_RSPEC_XML_REPORT so the results won't accumulate with duplicated xml tags in TMP_RSPEC_XML_REPORT
1272
+ FINAL_RSPEC_XML_REPORT = 'tmp/rspec_final_results.xml'
1273
+
1171
1274
  KnapsackPro::Hooks::Queue.after_subset_queue do |queue_id, subset_queue_id|
1172
- # TODO This must be the same path as value for rspec --out argument
1173
- old_xml_file = 'tmp/rspec.xml'
1174
- # move results to new_xml_file so the results won't accumulate with duplicated xml tags in old_xml_file
1175
- new_xml_file = 'tmp/rspec_final_results.xml'
1176
- FileUtils.mv(old_xml_file, new_xml_file) if File.exist?(old_xml_file)
1275
+ if File.exist?(TMP_RSPEC_XML_REPORT)
1276
+ FileUtils.mv(TMP_RSPEC_XML_REPORT, FINAL_RSPEC_XML_REPORT)
1277
+ end
1177
1278
  end
1178
1279
 
1179
1280
  #### How many API keys I need?
data/Rakefile CHANGED
@@ -1,4 +1,2 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'knapsack_pro'
3
-
4
- #KnapsackPro.load_tasks
@@ -10,6 +10,7 @@ MAP = {
10
10
  'queue:rspec' => KnapsackPro::Runners::Queue::RSpecRunner,
11
11
  'cucumber' => KnapsackPro::Runners::CucumberRunner,
12
12
  'minitest' => KnapsackPro::Runners::MinitestRunner,
13
+ 'test_unit' => KnapsackPro::Runners::TestUnitRunner,
13
14
  'spinach' => KnapsackPro::Runners::SpinachRunner,
14
15
  }
15
16
 
data/circle.yml CHANGED
@@ -3,3 +3,10 @@ machine:
3
3
  version: 2.4.0
4
4
  environment:
5
5
  CODECLIMATE_REPO_TOKEN: b6626e682a8e97e0c5978febc92c3526792a2d018b41b8e1b52689da37fb7d92
6
+ test:
7
+ override:
8
+ # Specify command explicitly because CircleCI 1.0 adds arguments to RSpec
9
+ # $ bundle exec rspec "--color --require spec_helper --format documentation" "" "spec"
10
+ # and this cause error because in tests we load test-unit gem that tries to parse
11
+ # the unknown arguments.
12
+ - bundle exec rspec spec
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'cucumber', '>= 0'
27
27
  spec.add_development_dependency 'spinach', '>= 0.8'
28
28
  spec.add_development_dependency 'minitest', '>= 5.0.0'
29
+ spec.add_development_dependency 'test-unit', '>= 3.0.0'
29
30
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 0'
30
31
  spec.add_development_dependency 'pry', '~> 0'
31
32
  spec.add_development_dependency 'vcr', '~> 2.9'
@@ -49,11 +49,13 @@ require_relative 'knapsack_pro/adapters/base_adapter'
49
49
  require_relative 'knapsack_pro/adapters/rspec_adapter'
50
50
  require_relative 'knapsack_pro/adapters/cucumber_adapter'
51
51
  require_relative 'knapsack_pro/adapters/minitest_adapter'
52
+ require_relative 'knapsack_pro/adapters/test_unit_adapter'
52
53
  require_relative 'knapsack_pro/adapters/spinach_adapter'
53
54
  require_relative 'knapsack_pro/runners/base_runner'
54
55
  require_relative 'knapsack_pro/runners/rspec_runner'
55
56
  require_relative 'knapsack_pro/runners/cucumber_runner'
56
57
  require_relative 'knapsack_pro/runners/minitest_runner'
58
+ require_relative 'knapsack_pro/runners/test_unit_runner'
57
59
  require_relative 'knapsack_pro/runners/spinach_runner'
58
60
  require_relative 'knapsack_pro/runners/queue/base_runner'
59
61
  require_relative 'knapsack_pro/runners/queue/rspec_runner'
@@ -0,0 +1,72 @@
1
+ module KnapsackPro
2
+ module Adapters
3
+ class TestUnitAdapter < BaseAdapter
4
+ TEST_DIR_PATTERN = 'test/**{,/*/**}/*_test.rb'
5
+ @@parent_of_test_dir = nil
6
+
7
+ def self.test_path(obj)
8
+ first_test = obj.tests.first
9
+ method = first_test.method_name
10
+ full_test_path = first_test.method(method).source_location.first
11
+ parent_of_test_dir_regexp = Regexp.new("^#{@@parent_of_test_dir}")
12
+ test_path = full_test_path.gsub(parent_of_test_dir_regexp, '.')
13
+ # test_path will look like ./test/dir/unit_test.rb
14
+ test_path
15
+ end
16
+
17
+ # Overrides the method from unit-test gem
18
+ # https://github.com/test-unit/test-unit/blob/master/lib/test/unit/testsuite.rb
19
+ module BindTimeTrackerTestUnitPlugin
20
+ def run_startup(result)
21
+ return if @test_case.nil?
22
+ KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::TestUnitAdapter.test_path(self)
23
+ KnapsackPro.tracker.start_timer
24
+ return if !@test_case.respond_to?(:startup)
25
+ begin
26
+ @test_case.startup
27
+ rescue Exception
28
+ raise unless handle_exception($!, result)
29
+ end
30
+ end
31
+
32
+ def run_shutdown(result)
33
+ return if @test_case.nil?
34
+ KnapsackPro.tracker.stop_timer
35
+ return if !@test_case.respond_to?(:shutdown)
36
+ begin
37
+ @test_case.shutdown
38
+ rescue Exception
39
+ raise unless handle_exception($!, result)
40
+ end
41
+ end
42
+ end
43
+
44
+ def bind_time_tracker
45
+ Test::Unit::TestSuite.send(:prepend, BindTimeTrackerTestUnitPlugin)
46
+
47
+ add_post_run_callback do
48
+ KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time)
49
+ end
50
+ end
51
+
52
+ def bind_save_report
53
+ add_post_run_callback do
54
+ KnapsackPro::Report.save
55
+ end
56
+ end
57
+
58
+ def set_test_helper_path(file_path)
59
+ test_dir_path = File.dirname(file_path)
60
+ @@parent_of_test_dir = File.expand_path('../', test_dir_path)
61
+ end
62
+
63
+ private
64
+
65
+ def add_post_run_callback(&block)
66
+ Test::Unit.at_exit do
67
+ block.call
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -136,6 +136,10 @@ module KnapsackPro
136
136
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST']
137
137
  end
138
138
 
139
+ def test_suite_token_test_unit
140
+ ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT']
141
+ end
142
+
139
143
  def test_suite_token_cucumber
140
144
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER']
141
145
  end
@@ -0,0 +1,28 @@
1
+ module KnapsackPro
2
+ module Runners
3
+ class TestUnitRunner < BaseRunner
4
+ def self.run(args)
5
+ ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN'] = KnapsackPro::Config::Env.test_suite_token_test_unit
6
+ ENV['KNAPSACK_PRO_RECORDING_ENABLED'] = 'true'
7
+
8
+ runner = new(KnapsackPro::Adapters::TestUnitAdapter)
9
+
10
+ if runner.test_files_to_execute_exist?
11
+ require 'test/unit'
12
+
13
+ cli_args =
14
+ (args || '').split +
15
+ runner.test_file_paths.map do |f|
16
+ File.expand_path(f)
17
+ end
18
+
19
+ exit Test::Unit::AutoRunner.run(
20
+ true,
21
+ runner.test_dir,
22
+ cli_args
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '0.50.1'
2
+ VERSION = '0.51.0'
3
3
  end
@@ -9,12 +9,14 @@ namespace :knapsack_pro do
9
9
  KnapsackPro::Adapters::RSpecAdapter
10
10
  when 'minitest'
11
11
  KnapsackPro::Adapters::MinitestAdapter
12
+ when 'test_unit'
13
+ KnapsackPro::Adapters::TestUnitAdapter
12
14
  when 'cucumber'
13
15
  KnapsackPro::Adapters::CucumberAdapter
14
16
  when 'spinach'
15
17
  KnapsackPro::Adapters::SpinachAdapter
16
18
  else
17
- raise('Provide adapter name like rspec, minitest, cucumber, spinach')
19
+ raise('Provide adapter name like rspec, minitest, test_unit, cucumber, spinach')
18
20
  end
19
21
 
20
22
  test_file_pattern = KnapsackPro::TestFilePattern.call(adapter_class)
@@ -0,0 +1,7 @@
1
+ require 'knapsack_pro'
2
+
3
+ namespace :knapsack_pro do
4
+ task :test_unit, [:test_unit_args] do |_, args|
5
+ KnapsackPro::Runners::TestUnitRunner.run(args[:test_unit_args])
6
+ end
7
+ end
@@ -0,0 +1,80 @@
1
+ require 'test/unit/testcase'
2
+
3
+ describe KnapsackPro::Adapters::TestUnitAdapter do
4
+ it do
5
+ expect(described_class::TEST_DIR_PATTERN).to eq 'test/**{,/*/**}/*_test.rb'
6
+ end
7
+
8
+ describe '.test_path' do
9
+ subject { described_class.test_path(obj) }
10
+
11
+ before do
12
+ parent_of_test_dir = File.expand_path('../../../', File.dirname(__FILE__))
13
+ parent_of_test_dir_regexp = Regexp.new("^#{parent_of_test_dir}")
14
+ described_class.class_variable_set(:@@parent_of_test_dir, parent_of_test_dir_regexp)
15
+ end
16
+
17
+ context 'when regular test' do
18
+ class FakeTestUnitTest
19
+ def method_name
20
+ "test_something"
21
+ end
22
+
23
+ def test_something
24
+ end
25
+ end
26
+
27
+ class FakeTestUnitTestSuite
28
+ def tests
29
+ [FakeTestUnitTest.new]
30
+ end
31
+ end
32
+
33
+ let(:obj) { FakeTestUnitTestSuite.new }
34
+
35
+ it { should eq './spec/knapsack_pro/adapters/test_unit_adapter_spec.rb' }
36
+ end
37
+ end
38
+
39
+ describe 'bind methods' do
40
+ describe '#bind_time_tracker' do
41
+ let(:logger) { instance_double(Logger) }
42
+ let(:global_time) { 'Global time: 01m 05s' }
43
+
44
+ it do
45
+ expect(Test::Unit::TestSuite).to receive(:send).with(:prepend, KnapsackPro::Adapters::TestUnitAdapter::BindTimeTrackerTestUnitPlugin)
46
+
47
+ expect(subject).to receive(:add_post_run_callback).and_yield
48
+
49
+ expect(KnapsackPro::Presenter).to receive(:global_time).and_return(global_time)
50
+ expect(KnapsackPro).to receive(:logger).and_return(logger)
51
+ expect(logger).to receive(:debug).with(global_time)
52
+
53
+ subject.bind_time_tracker
54
+ end
55
+ end
56
+
57
+ describe '#bind_save_report' do
58
+ it do
59
+ expect(subject).to receive(:add_post_run_callback).and_yield
60
+
61
+ expect(KnapsackPro::Report).to receive(:save)
62
+
63
+ subject.bind_save_report
64
+ end
65
+ end
66
+ end
67
+
68
+ describe '#set_test_helper_path' do
69
+ let(:adapter) { described_class.new }
70
+ let(:test_helper_path) { '/code/project/test/test_helper.rb' }
71
+
72
+ subject { adapter.set_test_helper_path(test_helper_path) }
73
+
74
+ after do
75
+ expect(described_class.class_variable_get(:@@parent_of_test_dir)).to eq '/code/project'
76
+ end
77
+
78
+ it { should eql '/code/project' }
79
+ end
80
+ end
@@ -513,6 +513,20 @@ describe KnapsackPro::Config::Env do
513
513
  end
514
514
  end
515
515
 
516
+ describe '.test_suite_token_test_unit' do
517
+ subject { described_class.test_suite_token_test_unit }
518
+
519
+ context 'when ENV exists' do
520
+ let(:test_suite_token_test_unit) { 'test-unit-token' }
521
+ before { stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT' => test_suite_token_test_unit }) }
522
+ it { should eq test_suite_token_test_unit }
523
+ end
524
+
525
+ context "when ENV doesn't exist" do
526
+ it { should be_nil }
527
+ end
528
+ end
529
+
516
530
  describe '.test_suite_token_cucumber' do
517
531
  subject { described_class.test_suite_token_cucumber }
518
532
 
@@ -0,0 +1,57 @@
1
+ require 'test/unit'
2
+
3
+ describe KnapsackPro::Runners::TestUnitRunner do
4
+ subject { described_class.new(KnapsackPro::Adapters::TestUnitAdapter) }
5
+
6
+ it { should be_kind_of KnapsackPro::Runners::BaseRunner }
7
+
8
+ describe '.run' do
9
+ let(:args) { '--verbose --order=random' }
10
+
11
+ subject { described_class.run(args) }
12
+
13
+ before do
14
+ stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT' => 'test-unit-token' })
15
+ end
16
+
17
+ context 'when test files were returned by Knapsack Pro API' do
18
+ it 'runs tests' do
19
+ test_file_paths = ['test-unit_fake/a_test.rb', 'test-unit_fake/b_test.rb']
20
+ runner = instance_double(described_class,
21
+ test_dir: 'test-unit_fake',
22
+ test_file_paths: test_file_paths,
23
+ test_files_to_execute_exist?: true)
24
+ expect(described_class).to receive(:new)
25
+ .with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner)
26
+
27
+ auto_runner_exit_code = 0
28
+ expect(Test::Unit::AutoRunner).to receive(:run) do |flag, test_dir, cli_args|
29
+ expect(flag).to be true
30
+ expect(test_dir).to eq 'test-unit_fake'
31
+ expect(cli_args.size).to eq 4
32
+ expect(cli_args[0]).to eq '--verbose'
33
+ expect(cli_args[1]).to eq '--order=random'
34
+ expect(cli_args[2]).to end_with 'test-unit_fake/a_test.rb'
35
+ expect(cli_args[3]).to end_with 'test-unit_fake/b_test.rb'
36
+ end.and_return(auto_runner_exit_code)
37
+ expect(described_class).to receive(:exit).with(auto_runner_exit_code)
38
+
39
+ subject
40
+
41
+ expect(ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN']).to eq 'test-unit-token'
42
+ expect(ENV['KNAPSACK_PRO_RECORDING_ENABLED']).to eq 'true'
43
+ end
44
+ end
45
+
46
+ context 'when test files were not returned by Knapsack Pro API' do
47
+ it "doesn't run tests" do
48
+ runner = instance_double(described_class,
49
+ test_files_to_execute_exist?: false)
50
+ expect(described_class).to receive(:new)
51
+ .with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner)
52
+
53
+ subject
54
+ end
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.50.1
4
+ version: 0.51.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-25 00:00:00.000000000 Z
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: 5.0.0
117
+ - !ruby/object:Gem::Dependency
118
+ name: test-unit
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 3.0.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 3.0.0
117
131
  - !ruby/object:Gem::Dependency
118
132
  name: codeclimate-test-reporter
119
133
  requirement: !ruby/object:Gem::Requirement
@@ -209,6 +223,7 @@ files:
209
223
  - lib/knapsack_pro/adapters/minitest_adapter.rb
210
224
  - lib/knapsack_pro/adapters/rspec_adapter.rb
211
225
  - lib/knapsack_pro/adapters/spinach_adapter.rb
226
+ - lib/knapsack_pro/adapters/test_unit_adapter.rb
212
227
  - lib/knapsack_pro/allocator.rb
213
228
  - lib/knapsack_pro/allocator_builder.rb
214
229
  - lib/knapsack_pro/base_allocator_builder.rb
@@ -253,6 +268,7 @@ files:
253
268
  - lib/knapsack_pro/runners/queue/rspec_runner.rb
254
269
  - lib/knapsack_pro/runners/rspec_runner.rb
255
270
  - lib/knapsack_pro/runners/spinach_runner.rb
271
+ - lib/knapsack_pro/runners/test_unit_runner.rb
256
272
  - lib/knapsack_pro/task_loader.rb
257
273
  - lib/knapsack_pro/test_file_cleaner.rb
258
274
  - lib/knapsack_pro/test_file_finder.rb
@@ -270,6 +286,7 @@ files:
270
286
  - lib/tasks/rspec.rake
271
287
  - lib/tasks/salt.rake
272
288
  - lib/tasks/spinach.rake
289
+ - lib/tasks/test_unit.rake
273
290
  - spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/invalid_test_suite_token.yml
274
291
  - spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/success.yml
275
292
  - spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/invalid_test_suite_token.yml
@@ -281,6 +298,7 @@ files:
281
298
  - spec/knapsack_pro/adapters/minitest_adapter_spec.rb
282
299
  - spec/knapsack_pro/adapters/rspec_adapter_spec.rb
283
300
  - spec/knapsack_pro/adapters/spinach_adapter_spec.rb
301
+ - spec/knapsack_pro/adapters/test_unit_adapter_spec.rb
284
302
  - spec/knapsack_pro/allocator_builder_spec.rb
285
303
  - spec/knapsack_pro/allocator_spec.rb
286
304
  - spec/knapsack_pro/base_allocator_builder_spec.rb
@@ -322,6 +340,7 @@ files:
322
340
  - spec/knapsack_pro/runners/queue/rspec_runner_spec.rb
323
341
  - spec/knapsack_pro/runners/rspec_runner_spec.rb
324
342
  - spec/knapsack_pro/runners/spinach_runner_spec.rb
343
+ - spec/knapsack_pro/runners/test_unit_runner_spec.rb
325
344
  - spec/knapsack_pro/task_loader_spec.rb
326
345
  - spec/knapsack_pro/test_file_cleaner_spec.rb
327
346
  - spec/knapsack_pro/test_file_finder_spec.rb
@@ -379,6 +398,7 @@ test_files:
379
398
  - spec/knapsack_pro/adapters/minitest_adapter_spec.rb
380
399
  - spec/knapsack_pro/adapters/rspec_adapter_spec.rb
381
400
  - spec/knapsack_pro/adapters/spinach_adapter_spec.rb
401
+ - spec/knapsack_pro/adapters/test_unit_adapter_spec.rb
382
402
  - spec/knapsack_pro/allocator_builder_spec.rb
383
403
  - spec/knapsack_pro/allocator_spec.rb
384
404
  - spec/knapsack_pro/base_allocator_builder_spec.rb
@@ -420,6 +440,7 @@ test_files:
420
440
  - spec/knapsack_pro/runners/queue/rspec_runner_spec.rb
421
441
  - spec/knapsack_pro/runners/rspec_runner_spec.rb
422
442
  - spec/knapsack_pro/runners/spinach_runner_spec.rb
443
+ - spec/knapsack_pro/runners/test_unit_runner_spec.rb
423
444
  - spec/knapsack_pro/task_loader_spec.rb
424
445
  - spec/knapsack_pro/test_file_cleaner_spec.rb
425
446
  - spec/knapsack_pro/test_file_finder_spec.rb