knapsack_pro 7.3.0 → 7.5.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
  SHA256:
3
- metadata.gz: 36aaf057fe65e4608728092873edfc63eaa1a667347b9a2b1a2d0d6b816be04b
4
- data.tar.gz: 02cf4fd1181eece28c72266525498af71a474b954ab919056121b56a135429df
3
+ metadata.gz: cea03959b8de66cd8cbb686deb3ac76129f9cce7ee24b1da2a0ef9e57dd790df
4
+ data.tar.gz: ec12a1f99f57207e967846df739a5dfea4a1423e6823431ee9cf26f1d2f9a473
5
5
  SHA512:
6
- metadata.gz: a6c8bf772b04582dcefb03d31e589930da021e60e43b6bb660b83215920030da0f553f24bb255435ce172a78c37fb80d18cf411f150d5b9cd4c5620ba9be91b1
7
- data.tar.gz: b543dc597458ad3e3fcfdf9de61117221832d8d472c96300adc8615ab7b36ab7d98951b5f849cff590a8f3db3e708f41051969f753fcaf9c5de0362ab4a6e85b
6
+ metadata.gz: cd53605f0d47ce2a3bc83410eb56d459a65aa1b75b169c420f5a11e3693b2aa7abee8e5b984eff35ab876de53809a2c113abb38b253e1e1b42726c817bccae6b
7
+ data.tar.gz: 93eaec09e20ba573cfb69b0f1ad2e8a04f5db2ab95637767a1abed0d8640cf131447b1adae67196998d73165232ea1a23e2c1fe547ab01b14436ace7d422edc5
data/.circleci/config.yml CHANGED
@@ -152,6 +152,12 @@ jobs:
152
152
  command: |
153
153
  export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular"
154
154
  bundle exec rake knapsack_pro:rspec
155
+ - run:
156
+ working_directory: ~/rails-app-with-knapsack_pro
157
+ command: |
158
+ # retry the same split ||
159
+ export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular"
160
+ bundle exec rake knapsack_pro:rspec
155
161
  - run:
156
162
  working_directory: ~/rails-app-with-knapsack_pro
157
163
  command: |
@@ -285,6 +291,7 @@ jobs:
285
291
  RACK_ENV: test
286
292
  KNAPSACK_PRO_ENDPOINT: https://api-staging.knapsackpro.com
287
293
  KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST: $KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST
294
+ KNAPSACK_PRO_RSPEC_DISABLED: true
288
295
  EXTRA_TEST_FILES_DELAY: 10
289
296
  - image: cimg/postgres:14.7
290
297
  environment:
@@ -308,6 +315,12 @@ jobs:
308
315
  command: |
309
316
  export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular"
310
317
  bundle exec rake knapsack_pro:minitest[--verbose]
318
+ - run:
319
+ working_directory: ~/rails-app-with-knapsack_pro
320
+ command: |
321
+ # retry the same split ||
322
+ export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular"
323
+ bundle exec rake knapsack_pro:minitest[--verbose]
311
324
 
312
325
  e2e-queue-minitest:
313
326
  parameters:
@@ -325,6 +338,7 @@ jobs:
325
338
  RACK_ENV: test
326
339
  KNAPSACK_PRO_ENDPOINT: https://api-staging.knapsackpro.com
327
340
  KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST: $KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST
341
+ KNAPSACK_PRO_RSPEC_DISABLED: true
328
342
  EXTRA_TEST_FILES_DELAY: 10
329
343
  - image: cimg/postgres:14.7
330
344
  environment:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ### 7.5.0
4
+ * Raise when `KNAPSACK_PRO_CI_NODE_TOTAL` or `KNAPSACK_PRO_CI_NODE_INDEX` is missing and can't be determined from supported CI environments, instead of defaulting to arbitrary numbers.
5
+
6
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/256
7
+
8
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v7.4.0...v7.5.0
9
+
10
+ ### 7.4.0
11
+ * Warn when `KNAPSACK_PRO_*` environment variables are set manually if their values could be automatically determined from supported CI environments.
12
+
13
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/254
14
+
15
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v7.3.0...v7.4.0
16
+
3
17
  ### 7.3.0
4
18
 
5
19
  * [Queue Mode][RSpec] Pass each batch of tests to the queue hooks: `KnapsackPro::Hooks::Queue.before_subset_queue` and `KnapsackPro::Hooks::Queue.after_subset_queue`
@@ -13,30 +13,27 @@ module KnapsackPro
13
13
 
14
14
  class << self
15
15
  def ci_node_total
16
- (ENV['KNAPSACK_PRO_CI_NODE_TOTAL'] ||
17
- ci_env_for(:node_total) ||
18
- 1).to_i
16
+ env_name = 'KNAPSACK_PRO_CI_NODE_TOTAL'
17
+ env_value = env_for(env_name, :node_total)
18
+
19
+ env_value ? env_value.to_i : raise_missing_env_for(env_name)
19
20
  end
20
21
 
21
22
  def ci_node_index
22
- (ENV['KNAPSACK_PRO_CI_NODE_INDEX'] ||
23
- ci_env_for(:node_index) ||
24
- 0).to_i
23
+ env_name = 'KNAPSACK_PRO_CI_NODE_INDEX'
24
+ env_value = env_for(env_name, :node_index)
25
+
26
+ env_value ? env_value.to_i : raise_missing_env_for(env_name)
25
27
  end
26
28
 
27
29
  def ci_node_build_id
28
30
  env_name = 'KNAPSACK_PRO_CI_NODE_BUILD_ID'
29
- ENV[env_name] ||
30
- ci_env_for(:node_build_id) ||
31
+ env_for(env_name, :node_build_id) ||
31
32
  raise("Missing environment variable #{env_name}. Read more at #{KnapsackPro::Urls::KNAPSACK_PRO_CI_NODE_BUILD_ID}")
32
33
  end
33
34
 
34
35
  def ci_node_retry_count
35
- (
36
- ENV['KNAPSACK_PRO_CI_NODE_RETRY_COUNT'] ||
37
- ci_env_for(:node_retry_count) ||
38
- 0
39
- ).to_i
36
+ (env_for('KNAPSACK_PRO_CI_NODE_RETRY_COUNT', :node_retry_count) || 0).to_i
40
37
  end
41
38
 
42
39
  def max_request_retries
@@ -47,23 +44,19 @@ module KnapsackPro
47
44
  end
48
45
 
49
46
  def commit_hash
50
- ENV['KNAPSACK_PRO_COMMIT_HASH'] ||
51
- ci_env_for(:commit_hash)
47
+ env_for('KNAPSACK_PRO_COMMIT_HASH', :commit_hash)
52
48
  end
53
49
 
54
50
  def branch
55
- ENV['KNAPSACK_PRO_BRANCH'] ||
56
- ci_env_for(:branch)
51
+ env_for('KNAPSACK_PRO_BRANCH', :branch)
57
52
  end
58
53
 
59
54
  def project_dir
60
- ENV['KNAPSACK_PRO_PROJECT_DIR'] ||
61
- ci_env_for(:project_dir)
55
+ env_for('KNAPSACK_PRO_PROJECT_DIR', :project_dir)
62
56
  end
63
57
 
64
58
  def user_seat
65
- ENV['KNAPSACK_PRO_USER_SEAT'] ||
66
- ci_env_for(:user_seat)
59
+ env_for('KNAPSACK_PRO_USER_SEAT', :user_seat)
67
60
  end
68
61
 
69
62
  def masked_user_seat
@@ -183,7 +176,7 @@ module KnapsackPro
183
176
  def fixed_queue_split
184
177
  @fixed_queue_split ||= begin
185
178
  env_name = 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT'
186
- computed = ENV.fetch(env_name, ci_env_for(:fixed_queue_split)).to_s
179
+ computed = env_for(env_name, :fixed_queue_split).to_s
187
180
 
188
181
  if !ENV.key?(env_name)
189
182
  KnapsackPro.logger.info("#{env_name} is not set. Using default value: #{computed}. Learn more at #{KnapsackPro::Urls::FIXED_QUEUE_SPLIT}")
@@ -249,10 +242,6 @@ module KnapsackPro
249
242
  end
250
243
  end
251
244
 
252
- def ci_env_for(env_name)
253
- detected_ci.new.send(env_name)
254
- end
255
-
256
245
  def detected_ci
257
246
  detected = KnapsackPro::Config::CI.constants.map do |constant|
258
247
  Object.const_get("KnapsackPro::Config::CI::#{constant}").new.detected
@@ -291,7 +280,26 @@ module KnapsackPro
291
280
  private
292
281
 
293
282
  def required_env(env_name)
294
- ENV[env_name] || raise("Missing environment variable #{env_name}")
283
+ ENV[env_name] || raise_missing_env_for(env_name)
284
+ end
285
+
286
+ def env_for(knapsack_env_name, ci_env_method)
287
+ knapsack_env_value = ENV[knapsack_env_name]
288
+ ci_env_value = ci_env_for(ci_env_method)
289
+
290
+ if !knapsack_env_value.nil? && !ci_env_value.nil? && knapsack_env_value != ci_env_value.to_s
291
+ KnapsackPro.logger.info("You have set the environment variable #{knapsack_env_name} to #{knapsack_env_value} which could be automatically determined from the CI environment as #{ci_env_value}.")
292
+ end
293
+
294
+ knapsack_env_value != nil ? knapsack_env_value : ci_env_value
295
+ end
296
+
297
+ def ci_env_for(env_name)
298
+ detected_ci.new.send(env_name)
299
+ end
300
+
301
+ def raise_missing_env_for(env_name)
302
+ raise("Missing environment variable #{env_name}")
295
303
  end
296
304
  end
297
305
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KnapsackPro
4
- VERSION = '7.3.0'
4
+ VERSION = '7.5.0'
5
5
  end
@@ -17,10 +17,46 @@ describe KnapsackPro::Config::Env do
17
17
 
18
18
  it { should eq 4 }
19
19
  end
20
+
21
+ context 'when both KNAPSACK_PRO_CI_NODE_TOTAL and CI environment have value' do
22
+ let(:logger) { instance_double(Logger, info: nil) }
23
+
24
+ before do
25
+ stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_TOTAL' => env_value })
26
+ expect(described_class).to receive(:ci_env_for).with(:node_total).and_return(ci_value)
27
+ allow(KnapsackPro).to receive(:logger).and_return(logger)
28
+ end
29
+
30
+ context 'when values are different' do
31
+ let(:env_value) { '5' }
32
+ let(:ci_value) { 4 }
33
+
34
+ it { should eq 5 }
35
+
36
+ it 'logs a warning' do
37
+ expect(logger).to receive(:info).with(
38
+ 'You have set the environment variable KNAPSACK_PRO_CI_NODE_TOTAL to 5 which could be automatically determined from the CI environment as 4.'
39
+ )
40
+ subject
41
+ end
42
+ end
43
+
44
+ context 'when values are the same' do
45
+ let(:env_value) { '5' }
46
+ let(:ci_value) { 5 }
47
+
48
+ it 'does not log a warning' do
49
+ expect(logger).not_to receive(:info)
50
+ subject
51
+ end
52
+ end
53
+ end
20
54
  end
21
55
 
22
56
  context "when ENV doesn't exist" do
23
- it { should eq 1 }
57
+ it 'raises' do
58
+ expect { subject }.to raise_error(/Missing environment variable KNAPSACK_PRO_CI_NODE_TOTAL/)
59
+ end
24
60
  end
25
61
  end
26
62
 
@@ -41,6 +77,40 @@ describe KnapsackPro::Config::Env do
41
77
  it { should eq 2 }
42
78
  end
43
79
 
80
+ context 'when both KNAPSACK_PRO_CI_NODE_INDEX and CI environment have value' do
81
+ let(:logger) { instance_double(Logger, info: nil) }
82
+
83
+ before do
84
+ stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_INDEX' => env_value })
85
+ expect(described_class).to receive(:ci_env_for).with(:node_index).and_return(ci_value)
86
+ allow(KnapsackPro).to receive(:logger).and_return(logger)
87
+ end
88
+
89
+ context 'when values are different' do
90
+ let(:env_value) { '3' }
91
+ let(:ci_value) { 2 }
92
+
93
+ it { should eq 3 }
94
+
95
+ it 'logs a warning' do
96
+ expect(logger).to receive(:info).with(
97
+ 'You have set the environment variable KNAPSACK_PRO_CI_NODE_INDEX to 3 which could be automatically determined from the CI environment as 2.'
98
+ )
99
+ subject
100
+ end
101
+ end
102
+
103
+ context 'when values are the same' do
104
+ let(:env_value) { '3' }
105
+ let(:ci_value) { 3 }
106
+
107
+ it 'does not log a warning' do
108
+ expect(logger).not_to receive(:info)
109
+ subject
110
+ end
111
+ end
112
+ end
113
+
44
114
  context 'when order of loading envs does matter' do
45
115
  context 'when GitLab CI' do
46
116
  before { stub_const("ENV", { 'CI_NODE_INDEX' => '2', 'GITLAB_CI' => 'true' }) }
@@ -50,7 +120,9 @@ describe KnapsackPro::Config::Env do
50
120
  end
51
121
 
52
122
  context "when ENV doesn't exist" do
53
- it { should eq 0 }
123
+ it 'raises' do
124
+ expect { subject }.to raise_error(/Missing environment variable KNAPSACK_PRO_CI_NODE_INDEX/)
125
+ end
54
126
  end
55
127
  end
56
128
 
@@ -70,6 +142,40 @@ describe KnapsackPro::Config::Env do
70
142
 
71
143
  it { should eq '8' }
72
144
  end
145
+
146
+ context 'when both KNAPSACK_PRO_CI_NODE_BUILD_ID and CI environment have value' do
147
+ let(:logger) { instance_double(Logger, info: nil) }
148
+
149
+ before do
150
+ stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_BUILD_ID' => env_value })
151
+ expect(described_class).to receive(:ci_env_for).with(:node_build_id).and_return(ci_value)
152
+ allow(KnapsackPro).to receive(:logger).and_return(logger)
153
+ end
154
+
155
+ context 'when values are different' do
156
+ let(:env_value) { '7' }
157
+ let(:ci_value) { '8' }
158
+
159
+ it { should eq '7' }
160
+
161
+ it 'logs a warning' do
162
+ expect(logger).to receive(:info).with(
163
+ 'You have set the environment variable KNAPSACK_PRO_CI_NODE_BUILD_ID to 7 which could be automatically determined from the CI environment as 8.'
164
+ )
165
+ subject
166
+ end
167
+ end
168
+
169
+ context 'when values are the same' do
170
+ let(:env_value) { '7' }
171
+ let(:ci_value) { '7' }
172
+
173
+ it 'does not log a warning' do
174
+ expect(logger).not_to receive(:info)
175
+ subject
176
+ end
177
+ end
178
+ end
73
179
  end
74
180
 
75
181
  context "when ENV does not exist" do
@@ -95,6 +201,40 @@ describe KnapsackPro::Config::Env do
95
201
 
96
202
  it { should eq 2 }
97
203
  end
204
+
205
+ context 'when both KNAPSACK_PRO_CI_NODE_RETRY_COUNT and CI environment have value' do
206
+ let(:logger) { instance_double(Logger, info: nil) }
207
+
208
+ before do
209
+ stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_RETRY_COUNT' => env_value })
210
+ expect(described_class).to receive(:ci_env_for).with(:node_retry_count).and_return(ci_value)
211
+ allow(KnapsackPro).to receive(:logger).and_return(logger)
212
+ end
213
+
214
+ context 'when values are different' do
215
+ let(:env_value) { '1' }
216
+ let(:ci_value) { 2 }
217
+
218
+ it { should eq 1 }
219
+
220
+ it 'logs a warning' do
221
+ expect(logger).to receive(:info).with(
222
+ 'You have set the environment variable KNAPSACK_PRO_CI_NODE_RETRY_COUNT to 1 which could be automatically determined from the CI environment as 2.'
223
+ )
224
+ subject
225
+ end
226
+ end
227
+
228
+ context 'when values are the same' do
229
+ let(:env_value) { '7' }
230
+ let(:ci_value) { '7' }
231
+
232
+ it 'does not log a warning' do
233
+ expect(logger).not_to receive(:info)
234
+ subject
235
+ end
236
+ end
237
+ end
98
238
  end
99
239
 
100
240
  context "when ENV doesn't exist" do
@@ -131,6 +271,40 @@ describe KnapsackPro::Config::Env do
131
271
 
132
272
  it { should eq 'fe61a08118d0d52e97c38666eba1eaf3' }
133
273
  end
274
+
275
+ context 'when both KNAPSACK_PRO_COMMIT_HASH and CI environment have value' do
276
+ let(:logger) { instance_double(Logger, info: nil) }
277
+
278
+ before do
279
+ stub_const("ENV", { 'KNAPSACK_PRO_COMMIT_HASH' => env_value })
280
+ expect(described_class).to receive(:ci_env_for).with(:commit_hash).and_return(ci_value)
281
+ allow(KnapsackPro).to receive(:logger).and_return(logger)
282
+ end
283
+
284
+ context 'when values are different' do
285
+ let(:env_value) { '3fa64859337f6e56409d49f865d13fd7' }
286
+ let(:ci_value) { 'fe61a08118d0d52e97c38666eba1eaf3' }
287
+
288
+ it { should eq '3fa64859337f6e56409d49f865d13fd7' }
289
+
290
+ it 'logs a warning' do
291
+ expect(logger).to receive(:info).with(
292
+ 'You have set the environment variable KNAPSACK_PRO_COMMIT_HASH to 3fa64859337f6e56409d49f865d13fd7 which could be automatically determined from the CI environment as fe61a08118d0d52e97c38666eba1eaf3.'
293
+ )
294
+ subject
295
+ end
296
+ end
297
+
298
+ context 'when values are the same' do
299
+ let(:env_value) { '3fa64859337f6e56409d49f865d13fd7' }
300
+ let(:ci_value) { '3fa64859337f6e56409d49f865d13fd7' }
301
+
302
+ it 'does not log a warning' do
303
+ expect(logger).not_to receive(:info)
304
+ subject
305
+ end
306
+ end
307
+ end
134
308
  end
135
309
 
136
310
  context "when ENV doesn't exist" do
@@ -154,6 +328,40 @@ describe KnapsackPro::Config::Env do
154
328
 
155
329
  it { should eq 'feature-branch' }
156
330
  end
331
+
332
+ context 'when both KNAPSACK_PRO_BRANCH and CI environment have value' do
333
+ let(:logger) { instance_double(Logger, info: nil) }
334
+
335
+ before do
336
+ stub_const("ENV", { 'KNAPSACK_PRO_BRANCH' => env_value })
337
+ expect(described_class).to receive(:ci_env_for).with(:branch).and_return(ci_value)
338
+ allow(KnapsackPro).to receive(:logger).and_return(logger)
339
+ end
340
+
341
+ context 'when values are different' do
342
+ let(:env_value) { 'master' }
343
+ let(:ci_value) { 'feature-branch' }
344
+
345
+ it { should eq 'master' }
346
+
347
+ it 'logs a warning' do
348
+ expect(logger).to receive(:info).with(
349
+ 'You have set the environment variable KNAPSACK_PRO_BRANCH to master which could be automatically determined from the CI environment as feature-branch.'
350
+ )
351
+ subject
352
+ end
353
+ end
354
+
355
+ context 'when values are the same' do
356
+ let(:env_value) { 'master' }
357
+ let(:ci_value) { 'master' }
358
+
359
+ it 'does not log a warning' do
360
+ expect(logger).not_to receive(:info)
361
+ subject
362
+ end
363
+ end
364
+ end
157
365
  end
158
366
 
159
367
  context "when ENV doesn't exist" do
@@ -177,6 +385,40 @@ describe KnapsackPro::Config::Env do
177
385
 
178
386
  it { should eq '/home/runner/myapp' }
179
387
  end
388
+
389
+ context 'when both KNAPSACK_PRO_PROJECT_DIR and CI environment have value' do
390
+ let(:logger) { instance_double(Logger, info: nil) }
391
+
392
+ before do
393
+ stub_const("ENV", { 'KNAPSACK_PRO_PROJECT_DIR' => env_value })
394
+ expect(described_class).to receive(:ci_env_for).with(:project_dir).and_return(ci_value)
395
+ allow(KnapsackPro).to receive(:logger).and_return(logger)
396
+ end
397
+
398
+ context 'when values are different' do
399
+ let(:env_value) { '/home/user/myapp' }
400
+ let(:ci_value) { '/home/runner/myapp' }
401
+
402
+ it { should eq '/home/user/myapp' }
403
+
404
+ it 'logs a warning' do
405
+ expect(logger).to receive(:info).with(
406
+ 'You have set the environment variable KNAPSACK_PRO_PROJECT_DIR to /home/user/myapp which could be automatically determined from the CI environment as /home/runner/myapp.'
407
+ )
408
+ subject
409
+ end
410
+ end
411
+
412
+ context 'when values are the same' do
413
+ let(:env_value) { '/home/user/myapp' }
414
+ let(:ci_value) { '/home/user/myapp' }
415
+
416
+ it 'does not log a warning' do
417
+ expect(logger).not_to receive(:info)
418
+ subject
419
+ end
420
+ end
421
+ end
180
422
  end
181
423
 
182
424
  context "when ENV doesn't exist" do
@@ -200,6 +442,40 @@ describe KnapsackPro::Config::Env do
200
442
 
201
443
  it { should eq 'Jane Doe' }
202
444
  end
445
+
446
+ context 'when both KNAPSACK_PRO_USER_SEAT and CI environment have value' do
447
+ let(:logger) { instance_double(Logger, info: nil) }
448
+
449
+ before do
450
+ stub_const("ENV", { 'KNAPSACK_PRO_USER_SEAT' => env_value })
451
+ expect(described_class).to receive(:ci_env_for).with(:user_seat).and_return(ci_value)
452
+ allow(KnapsackPro).to receive(:logger).and_return(logger)
453
+ end
454
+
455
+ context 'when values are different' do
456
+ let(:env_value) { 'John Doe' }
457
+ let(:ci_value) { 'Jane Doe' }
458
+
459
+ it { should eq 'John Doe' }
460
+
461
+ it 'logs a warning' do
462
+ expect(logger).to receive(:info).with(
463
+ 'You have set the environment variable KNAPSACK_PRO_USER_SEAT to John Doe which could be automatically determined from the CI environment as Jane Doe.'
464
+ )
465
+ subject
466
+ end
467
+ end
468
+
469
+ context 'when values are the same' do
470
+ let(:env_value) { 'John Doe' }
471
+ let(:ci_value) { 'John Doe' }
472
+
473
+ it 'does not log a warning' do
474
+ expect(logger).not_to receive(:info)
475
+ subject
476
+ end
477
+ end
478
+ end
203
479
  end
204
480
 
205
481
  context "when ENV doesn't exist" do
@@ -345,7 +621,6 @@ describe KnapsackPro::Config::Env do
345
621
  end
346
622
  end
347
623
 
348
-
349
624
  describe '.regular_mode?' do
350
625
  subject { described_class.regular_mode? }
351
626
 
@@ -645,11 +920,18 @@ describe KnapsackPro::Config::Env do
645
920
  ['Unsupported CI', {}],
646
921
  ].each do |ci, env|
647
922
  it "on #{ci} it is false" do
923
+ stub_const("ENV", env.merge({ 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => 'false' }))
924
+
648
925
  logger = instance_double(Logger)
649
926
  allow(KnapsackPro).to receive(:logger).and_return(logger)
650
- expect(logger).not_to receive(:info)
651
-
652
- stub_const("ENV", env.merge({ 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => 'false' }))
927
+ ci_env = described_class.detected_ci.new.fixed_queue_split
928
+ if ci_env == false
929
+ expect(logger).not_to receive(:info)
930
+ else
931
+ expect(logger).to receive(:info).with(
932
+ 'You have set the environment variable KNAPSACK_PRO_FIXED_QUEUE_SPLIT to false which could be automatically determined from the CI environment as true.'
933
+ )
934
+ end
653
935
 
654
936
  expect(subject).to eq(false)
655
937
  end
@@ -673,11 +955,18 @@ describe KnapsackPro::Config::Env do
673
955
  ['Unsupported CI', {}],
674
956
  ].each do |ci, env|
675
957
  it "on #{ci} it is true" do
958
+ stub_const("ENV", env.merge({ 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => 'true' }))
959
+
676
960
  logger = instance_double(Logger)
677
961
  allow(KnapsackPro).to receive(:logger).and_return(logger)
678
- expect(logger).not_to receive(:info)
679
-
680
- stub_const("ENV", env.merge({ 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => 'true' }))
962
+ ci_env = described_class.detected_ci.new.fixed_queue_split
963
+ if ci_env == true
964
+ expect(logger).not_to receive(:info)
965
+ else
966
+ expect(logger).to receive(:info).with(
967
+ 'You have set the environment variable KNAPSACK_PRO_FIXED_QUEUE_SPLIT to true which could be automatically determined from the CI environment as false.'
968
+ )
969
+ end
681
970
 
682
971
  expect(subject).to eq(true)
683
972
  end
@@ -702,12 +991,12 @@ describe KnapsackPro::Config::Env do
702
991
  ['Unsupported CI', {}, true],
703
992
  ].each do |ci, env, expected|
704
993
  it "on #{ci} it is #{expected}" do
994
+ stub_const("ENV", env)
995
+
705
996
  logger = instance_double(Logger)
706
997
  expect(KnapsackPro).to receive(:logger).and_return(logger)
707
998
  expect(logger).to receive(:info).with("KNAPSACK_PRO_FIXED_QUEUE_SPLIT is not set. Using default value: #{expected}. Learn more at #{KnapsackPro::Urls::FIXED_QUEUE_SPLIT}")
708
999
 
709
- stub_const("ENV", env)
710
-
711
1000
  expect(subject).to eq(expected)
712
1001
  end
713
1002
  end
@@ -36,13 +36,11 @@ describe KnapsackPro do
36
36
  stub_const('ENV', {
37
37
  'KNAPSACK_PRO_LOG_DIR' => 'log',
38
38
  })
39
-
40
- expect(Logger).to receive(:new).with('log/knapsack_pro_node_0.log').and_return(logger)
41
- expect(logger).to receive(:level=).with(Logger::INFO)
42
- expect(KnapsackPro::LoggerWrapper).to receive(:new).with(logger).and_return(logger_wrapper)
43
39
  end
44
40
 
45
- it { should eql logger_wrapper }
41
+ it 'raises' do
42
+ expect { subject }.to raise_error(/Missing environment variable KNAPSACK_PRO_CI_NODE_INDEX/)
43
+ end
46
44
  end
47
45
  end
48
46
 
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: 7.3.0
4
+ version: 7.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-17 00:00:00.000000000 Z
11
+ date: 2024-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -415,7 +415,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
415
415
  - !ruby/object:Gem::Version
416
416
  version: '0'
417
417
  requirements: []
418
- rubygems_version: 3.4.19
418
+ rubygems_version: 3.4.10
419
419
  signing_key:
420
420
  specification_version: 4
421
421
  summary: Knapsack Pro splits tests across parallel CI nodes and ensures each parallel