knapsack_pro 1.20.0 → 1.22.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -0
  3. data/README.md +42 -17
  4. data/lib/knapsack_pro.rb +6 -0
  5. data/lib/knapsack_pro/adapters/base_adapter.rb +16 -0
  6. data/lib/knapsack_pro/adapters/rspec_adapter.rb +11 -9
  7. data/lib/knapsack_pro/allocator.rb +7 -5
  8. data/lib/knapsack_pro/allocator_builder.rb +2 -1
  9. data/lib/knapsack_pro/base_allocator_builder.rb +41 -10
  10. data/lib/knapsack_pro/build_distribution_fetcher.rb +57 -0
  11. data/lib/knapsack_pro/client/api/v1/build_distributions.rb +13 -0
  12. data/lib/knapsack_pro/client/connection.rb +33 -15
  13. data/lib/knapsack_pro/config/env.rb +4 -0
  14. data/lib/knapsack_pro/formatters/rspec_json_formatter.rb +1 -1
  15. data/lib/knapsack_pro/queue_allocator.rb +7 -5
  16. data/lib/knapsack_pro/queue_allocator_builder.rb +2 -1
  17. data/lib/knapsack_pro/report.rb +1 -1
  18. data/lib/knapsack_pro/runners/queue/cucumber_runner.rb +10 -1
  19. data/lib/knapsack_pro/runners/queue/rspec_runner.rb +7 -0
  20. data/lib/knapsack_pro/runners/rspec_runner.rb +5 -2
  21. data/lib/knapsack_pro/slow_test_file_determiner.rb +33 -0
  22. data/lib/knapsack_pro/slow_test_file_finder.rb +27 -0
  23. data/lib/knapsack_pro/test_case_detectors/rspec_test_example_detector.rb +26 -7
  24. data/lib/knapsack_pro/test_case_mergers/base_merger.rb +29 -0
  25. data/lib/knapsack_pro/test_case_mergers/rspec_merger.rb +34 -0
  26. data/lib/knapsack_pro/test_file_finder.rb +43 -5
  27. data/lib/knapsack_pro/test_files_with_test_cases_composer.rb +22 -0
  28. data/lib/knapsack_pro/version.rb +1 -1
  29. data/spec/knapsack_pro/adapters/base_adapter_spec.rb +55 -0
  30. data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +61 -25
  31. data/spec/knapsack_pro/allocator_builder_spec.rb +7 -3
  32. data/spec/knapsack_pro/allocator_spec.rb +7 -5
  33. data/spec/knapsack_pro/base_allocator_builder_spec.rb +79 -27
  34. data/spec/knapsack_pro/build_distribution_fetcher_spec.rb +89 -0
  35. data/spec/knapsack_pro/client/api/v1/build_distributions_spec.rb +31 -0
  36. data/spec/knapsack_pro/client/connection_spec.rb +202 -104
  37. data/spec/knapsack_pro/config/env_spec.rb +14 -0
  38. data/spec/knapsack_pro/queue_allocator_builder_spec.rb +7 -3
  39. data/spec/knapsack_pro/queue_allocator_spec.rb +7 -5
  40. data/spec/knapsack_pro/report_spec.rb +1 -1
  41. data/spec/knapsack_pro/runners/queue/cucumber_runner_spec.rb +38 -25
  42. data/spec/knapsack_pro/runners/rspec_runner_spec.rb +4 -4
  43. data/spec/knapsack_pro/slow_test_file_determiner_spec.rb +74 -0
  44. data/spec/knapsack_pro/slow_test_file_finder_spec.rb +43 -0
  45. data/spec/knapsack_pro/test_case_detectors/rspec_test_example_detector_spec.rb +83 -37
  46. data/spec/knapsack_pro/test_case_mergers/base_merger_spec.rb +27 -0
  47. data/spec/knapsack_pro/test_case_mergers/rspec_merger_spec.rb +59 -0
  48. data/spec/knapsack_pro/test_file_finder_spec.rb +105 -29
  49. data/spec/knapsack_pro/test_files_with_test_cases_composer_spec.rb +41 -0
  50. metadata +20 -2
@@ -0,0 +1,59 @@
1
+ describe KnapsackPro::TestCaseMergers::RSpecMerger do
2
+ describe '#call' do
3
+ subject { described_class.new(test_files).call }
4
+
5
+ context 'when all test files are not test example paths' do
6
+ let(:test_files) do
7
+ [
8
+ { 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
9
+ { 'path' => 'spec/b_spec.rb', 'time_execution' => 2.2 },
10
+ ]
11
+ end
12
+
13
+ it do
14
+ expect(subject).to eq([
15
+ { 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
16
+ { 'path' => 'spec/b_spec.rb', 'time_execution' => 2.2 },
17
+ ])
18
+ end
19
+ end
20
+
21
+ context 'when test files have test example paths' do
22
+ let(:test_files) do
23
+ [
24
+ { 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
25
+ # test example paths
26
+ { 'path' => 'spec/test_case_spec.rb[1:1]', 'time_execution' => 2.2 },
27
+ { 'path' => 'spec/test_case_spec.rb[1:2]', 'time_execution' => 0.8 },
28
+ ]
29
+ end
30
+
31
+ it 'returns merged paths for test examples and sum of their time_execution' do
32
+ expect(subject).to eq([
33
+ { 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
34
+ { 'path' => 'spec/test_case_spec.rb', 'time_execution' => 3.0 },
35
+ ])
36
+ end
37
+ end
38
+
39
+ context 'when test files have test example paths and at the same time test file path for test example path is present as full test file path' do
40
+ let(:test_files) do
41
+ [
42
+ { 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
43
+ # full test file path is present despite existing test example paths
44
+ { 'path' => 'spec/test_case_spec.rb', 'time_execution' => 1.0 },
45
+ # test example paths
46
+ { 'path' => 'spec/test_case_spec.rb[1:1]', 'time_execution' => 2.2 },
47
+ { 'path' => 'spec/test_case_spec.rb[1:2]', 'time_execution' => 0.8 },
48
+ ]
49
+ end
50
+
51
+ it 'returns merged paths for test examples and sum of their time_execution' do
52
+ expect(subject).to eq([
53
+ { 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
54
+ { 'path' => 'spec/test_case_spec.rb', 'time_execution' => 4.0 },
55
+ ])
56
+ end
57
+ end
58
+ end
59
+ end
@@ -7,29 +7,105 @@ describe KnapsackPro::TestFileFinder do
7
7
 
8
8
  before do
9
9
  test_file_finder = instance_double(described_class, call: test_files)
10
- expect(described_class).to receive(:new).with(test_file_pattern).and_return(test_file_finder)
10
+ expect(described_class).to receive(:new).with(test_file_pattern, true).and_return(test_file_finder)
11
11
  end
12
12
 
13
13
  it { should eq test_files }
14
14
  end
15
15
 
16
+ describe '.slow_test_files_by_pattern' do
17
+ let(:adapter_class) { double }
18
+
19
+ subject { described_class.slow_test_files_by_pattern(adapter_class) }
20
+
21
+ before do
22
+ expect(KnapsackPro::Config::Env).to receive(:slow_test_file_pattern).at_least(1).and_return(slow_test_file_pattern)
23
+ end
24
+
25
+ context 'when slow_test_file_pattern is present' do
26
+ let(:slow_test_file_pattern) { double }
27
+ let(:test_file_entities) do
28
+ [
29
+ { 'path' => 'a_spec.rb' },
30
+ { 'path' => 'b_spec.rb' },
31
+ { 'path' => 'c_spec.rb' },
32
+ ]
33
+ end
34
+ let(:slow_test_file_entities) do
35
+ [
36
+ { 'path' => 'b_spec.rb' },
37
+ { 'path' => 'c_spec.rb' },
38
+ { 'path' => 'd_spec.rb' },
39
+ ]
40
+ end
41
+
42
+ it do
43
+ test_file_pattern = double
44
+ expect(KnapsackPro::TestFilePattern).to receive(:call).with(adapter_class).and_return(test_file_pattern)
45
+ expect(described_class).to receive(:call).with(test_file_pattern).and_return(test_file_entities)
46
+
47
+ expect(described_class).to receive(:call).with(slow_test_file_pattern, test_file_list_enabled: false).and_return(slow_test_file_entities)
48
+
49
+ expect(subject).to eq([
50
+ { 'path' => 'b_spec.rb' },
51
+ { 'path' => 'c_spec.rb' },
52
+ ])
53
+ end
54
+ end
55
+
56
+ context 'when slow_test_file_pattern is not present' do
57
+ let(:slow_test_file_pattern) { nil }
58
+
59
+ it do
60
+ expect { subject }.to raise_error RuntimeError, 'KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN is not defined'
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '.select_test_files_that_can_be_run' do
66
+ let(:adapter_class) { double }
67
+ let(:test_file_entities_to_run) do
68
+ [
69
+ { 'path' => 'a_spec.rb' },
70
+ { 'path' => 'b_spec.rb' },
71
+ { 'path' => 'not_existing_on_disk_spec.rb' },
72
+ ]
73
+ end
74
+ # test files existing on disk
75
+ let(:test_file_entities) do
76
+ [
77
+ { 'path' => 'a_spec.rb' },
78
+ { 'path' => 'b_spec.rb' },
79
+ { 'path' => 'c_spec.rb' },
80
+ ]
81
+ end
82
+
83
+ subject { described_class.select_test_files_that_can_be_run(adapter_class, test_file_entities_to_run) }
84
+
85
+ it do
86
+ test_file_pattern = double
87
+ expect(KnapsackPro::TestFilePattern).to receive(:call).with(adapter_class).and_return(test_file_pattern)
88
+ expect(described_class).to receive(:call).with(test_file_pattern).and_return(test_file_entities)
89
+
90
+ expect(subject).to eq([
91
+ { 'path' => 'a_spec.rb' },
92
+ { 'path' => 'b_spec.rb' },
93
+ ])
94
+ end
95
+ end
96
+
16
97
  describe '#call' do
98
+ let(:test_file_list_enabled) { true }
17
99
  let(:test_file_pattern) { 'spec_fake/**{,/*/**}/*_spec.rb' }
18
100
 
19
- subject { described_class.new(test_file_pattern).call }
101
+ subject { described_class.new(test_file_pattern, test_file_list_enabled).call }
20
102
 
21
103
  context 'when KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN is not defined' do
22
104
  it do
23
105
  should eq([
24
- {
25
- 'path' => 'spec_fake/controllers/users_controller_spec.rb',
26
- },
27
- {
28
- 'path' => 'spec_fake/models/admin_spec.rb',
29
- },
30
- {
31
- 'path' => 'spec_fake/models/user_spec.rb',
32
- },
106
+ { 'path' => 'spec_fake/controllers/users_controller_spec.rb' },
107
+ { 'path' => 'spec_fake/models/admin_spec.rb' },
108
+ { 'path' => 'spec_fake/models/user_spec.rb' },
33
109
  ])
34
110
  end
35
111
  end
@@ -43,12 +119,8 @@ describe KnapsackPro::TestFileFinder do
43
119
 
44
120
  it do
45
121
  should eq([
46
- {
47
- 'path' => 'spec_fake/models/admin_spec.rb',
48
- },
49
- {
50
- 'path' => 'spec_fake/models/user_spec.rb',
51
- },
122
+ { 'path' => 'spec_fake/models/admin_spec.rb' },
123
+ { 'path' => 'spec_fake/models/user_spec.rb' },
52
124
  ])
53
125
  end
54
126
  end
@@ -63,20 +135,24 @@ describe KnapsackPro::TestFileFinder do
63
135
 
64
136
  it do
65
137
  expect(subject).to eq([
66
- {
67
- 'path' => 'spec/bar_spec.rb',
68
- },
69
- {
70
- 'path' => 'spec/foo_spec.rb',
71
- },
72
- {
73
- 'path' => 'spec/time_helpers_spec.rb:10',
74
- },
75
- {
76
- 'path' => 'spec/time_helpers_spec.rb:38',
77
- },
138
+ { 'path' => 'spec/bar_spec.rb' },
139
+ { 'path' => 'spec/foo_spec.rb' },
140
+ { 'path' => 'spec/time_helpers_spec.rb:10' },
141
+ { 'path' => 'spec/time_helpers_spec.rb:38' },
78
142
  ])
79
143
  end
144
+
145
+ context 'when test_file_list_enabled=false' do
146
+ let(:test_file_list_enabled) { false }
147
+
148
+ it do
149
+ should eq([
150
+ { 'path' => 'spec_fake/controllers/users_controller_spec.rb' },
151
+ { 'path' => 'spec_fake/models/admin_spec.rb' },
152
+ { 'path' => 'spec_fake/models/user_spec.rb' },
153
+ ])
154
+ end
155
+ end
80
156
  end
81
157
  end
82
158
  end
@@ -0,0 +1,41 @@
1
+ describe KnapsackPro::TestFilesWithTestCasesComposer do
2
+ let(:test_files) do
3
+ [
4
+ { 'path' => 'spec/a_spec.rb' },
5
+ { 'path' => 'spec/b_spec.rb' },
6
+ { 'path' => 'spec/c_spec.rb' },
7
+ { 'path' => 'spec/slow_1_spec.rb' },
8
+ { 'path' => 'spec/slow_2_spec.rb' },
9
+ ]
10
+ end
11
+ let(:slow_test_files) do
12
+ [
13
+ { 'path' => 'spec/slow_1_spec.rb', 'time_execution' => 1.0 },
14
+ { 'path' => 'spec/slow_2_spec.rb', 'time_execution' => 2.0 },
15
+ ]
16
+ end
17
+ let(:test_file_cases) do
18
+ [
19
+ { 'path' => 'spec/slow_1_spec.rb[1:1]' },
20
+ { 'path' => 'spec/slow_1_spec.rb[1:2]' },
21
+ { 'path' => 'spec/slow_2_spec.rb[1:1:1]' },
22
+ { 'path' => 'spec/slow_2_spec.rb[1:1:2]' },
23
+ { 'path' => 'spec/slow_2_spec.rb[1:1:3]' },
24
+ ]
25
+ end
26
+
27
+ subject { described_class.call(test_files, slow_test_files, test_file_cases) }
28
+
29
+ it 'returns test files that are not slow and test file cases for slow test files' do
30
+ expect(subject).to eq([
31
+ { 'path' => 'spec/a_spec.rb' },
32
+ { 'path' => 'spec/b_spec.rb' },
33
+ { 'path' => 'spec/c_spec.rb' },
34
+ { 'path' => 'spec/slow_1_spec.rb[1:1]' },
35
+ { 'path' => 'spec/slow_1_spec.rb[1:2]' },
36
+ { 'path' => 'spec/slow_2_spec.rb[1:1:1]' },
37
+ { 'path' => 'spec/slow_2_spec.rb[1:1:2]' },
38
+ { 'path' => 'spec/slow_2_spec.rb[1:1:3]' },
39
+ ])
40
+ end
41
+ 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: 1.20.0
4
+ version: 1.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-09 00:00:00.000000000 Z
11
+ date: 2020-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -229,6 +229,7 @@ files:
229
229
  - lib/knapsack_pro/allocator.rb
230
230
  - lib/knapsack_pro/allocator_builder.rb
231
231
  - lib/knapsack_pro/base_allocator_builder.rb
232
+ - lib/knapsack_pro/build_distribution_fetcher.rb
232
233
  - lib/knapsack_pro/client/api/action.rb
233
234
  - lib/knapsack_pro/client/api/v1/base.rb
234
235
  - lib/knapsack_pro/client/api/v1/build_distributions.rb
@@ -281,12 +282,17 @@ files:
281
282
  - lib/knapsack_pro/runners/rspec_runner.rb
282
283
  - lib/knapsack_pro/runners/spinach_runner.rb
283
284
  - lib/knapsack_pro/runners/test_unit_runner.rb
285
+ - lib/knapsack_pro/slow_test_file_determiner.rb
286
+ - lib/knapsack_pro/slow_test_file_finder.rb
284
287
  - lib/knapsack_pro/task_loader.rb
285
288
  - lib/knapsack_pro/test_case_detectors/rspec_test_example_detector.rb
289
+ - lib/knapsack_pro/test_case_mergers/base_merger.rb
290
+ - lib/knapsack_pro/test_case_mergers/rspec_merger.rb
286
291
  - lib/knapsack_pro/test_file_cleaner.rb
287
292
  - lib/knapsack_pro/test_file_finder.rb
288
293
  - lib/knapsack_pro/test_file_pattern.rb
289
294
  - lib/knapsack_pro/test_file_presenter.rb
295
+ - lib/knapsack_pro/test_files_with_test_cases_composer.rb
290
296
  - lib/knapsack_pro/test_flat_distributor.rb
291
297
  - lib/knapsack_pro/tracker.rb
292
298
  - lib/knapsack_pro/utils.rb
@@ -317,6 +323,7 @@ files:
317
323
  - spec/knapsack_pro/allocator_builder_spec.rb
318
324
  - spec/knapsack_pro/allocator_spec.rb
319
325
  - spec/knapsack_pro/base_allocator_builder_spec.rb
326
+ - spec/knapsack_pro/build_distribution_fetcher_spec.rb
320
327
  - spec/knapsack_pro/client/api/action_spec.rb
321
328
  - spec/knapsack_pro/client/api/v1/base_spec.rb
322
329
  - spec/knapsack_pro/client/api/v1/build_distributions_spec.rb
@@ -365,12 +372,17 @@ files:
365
372
  - spec/knapsack_pro/runners/rspec_runner_spec.rb
366
373
  - spec/knapsack_pro/runners/spinach_runner_spec.rb
367
374
  - spec/knapsack_pro/runners/test_unit_runner_spec.rb
375
+ - spec/knapsack_pro/slow_test_file_determiner_spec.rb
376
+ - spec/knapsack_pro/slow_test_file_finder_spec.rb
368
377
  - spec/knapsack_pro/task_loader_spec.rb
369
378
  - spec/knapsack_pro/test_case_detectors/rspec_test_example_detector_spec.rb
379
+ - spec/knapsack_pro/test_case_mergers/base_merger_spec.rb
380
+ - spec/knapsack_pro/test_case_mergers/rspec_merger_spec.rb
370
381
  - spec/knapsack_pro/test_file_cleaner_spec.rb
371
382
  - spec/knapsack_pro/test_file_finder_spec.rb
372
383
  - spec/knapsack_pro/test_file_pattern_spec.rb
373
384
  - spec/knapsack_pro/test_file_presenter_spec.rb
385
+ - spec/knapsack_pro/test_files_with_test_cases_composer_spec.rb
374
386
  - spec/knapsack_pro/test_flat_distributor_spec.rb
375
387
  - spec/knapsack_pro/tracker_spec.rb
376
388
  - spec/knapsack_pro/utils_spec.rb
@@ -431,6 +443,7 @@ test_files:
431
443
  - spec/knapsack_pro/allocator_builder_spec.rb
432
444
  - spec/knapsack_pro/allocator_spec.rb
433
445
  - spec/knapsack_pro/base_allocator_builder_spec.rb
446
+ - spec/knapsack_pro/build_distribution_fetcher_spec.rb
434
447
  - spec/knapsack_pro/client/api/action_spec.rb
435
448
  - spec/knapsack_pro/client/api/v1/base_spec.rb
436
449
  - spec/knapsack_pro/client/api/v1/build_distributions_spec.rb
@@ -479,12 +492,17 @@ test_files:
479
492
  - spec/knapsack_pro/runners/rspec_runner_spec.rb
480
493
  - spec/knapsack_pro/runners/spinach_runner_spec.rb
481
494
  - spec/knapsack_pro/runners/test_unit_runner_spec.rb
495
+ - spec/knapsack_pro/slow_test_file_determiner_spec.rb
496
+ - spec/knapsack_pro/slow_test_file_finder_spec.rb
482
497
  - spec/knapsack_pro/task_loader_spec.rb
483
498
  - spec/knapsack_pro/test_case_detectors/rspec_test_example_detector_spec.rb
499
+ - spec/knapsack_pro/test_case_mergers/base_merger_spec.rb
500
+ - spec/knapsack_pro/test_case_mergers/rspec_merger_spec.rb
484
501
  - spec/knapsack_pro/test_file_cleaner_spec.rb
485
502
  - spec/knapsack_pro/test_file_finder_spec.rb
486
503
  - spec/knapsack_pro/test_file_pattern_spec.rb
487
504
  - spec/knapsack_pro/test_file_presenter_spec.rb
505
+ - spec/knapsack_pro/test_files_with_test_cases_composer_spec.rb
488
506
  - spec/knapsack_pro/test_flat_distributor_spec.rb
489
507
  - spec/knapsack_pro/tracker_spec.rb
490
508
  - spec/knapsack_pro/utils_spec.rb