knapsack_pro 5.3.4 → 5.4.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
  SHA256:
3
- metadata.gz: 6952ceb372cbcc2dc8c2c5514f0fe68bc4be51572199168e3d7f7992eabdfe43
4
- data.tar.gz: '077863b80cab5c090ad84c62cbb0c2d680757ea19da59e94c92cb9ee2770ba90'
3
+ metadata.gz: 9403659bbc5c95b9b6f0998b7ffdbffbe919522811c651644428eea2df6f3887
4
+ data.tar.gz: 139709a119b184958ef73d2268bfeca618f5456c0a410e6198baf8a4d269e05b
5
5
  SHA512:
6
- metadata.gz: 3ba6a868b796019d571c077131e1cd33016bee27e7a8cbd1b1d35cfe31532c2049734d1cf24686ac5ef63a881a82ed0c3d811d4e04ccf17ba0444a856121e363
7
- data.tar.gz: a717af5c831cfd8984ac2c2d691b557dd7cd919e1e7a223d9347eac8d28345700bdcefdf50d0fc5ab10a23c2c9dd4811e95198c443530d83006e7baeee898dbb
6
+ metadata.gz: 9a5152b40b810546160663243f259b82de186be4c01169cb2881315eadbacaf50a47bc6a8f851dcf0c08aa0f392aeaff3d618886f0cd8aaa1cbb06eac6d2f8b2
7
+ data.tar.gz: e20d7cb45f17fffd7420d16ed15cca4c44a0bc022407f97871d6e03290b09fd69da11e06d5dced21a77dcab059c00394909c7977eed849496e805f18a99c7580
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ### 5.4.0
4
+
5
+ * Send to the API the CI provider with a header
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/216
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v5.3.5...v5.4.0
10
+
11
+ ### 5.3.5
12
+
13
+ * Handle RSpec exceptions when running RSpec in Queue Mode
14
+
15
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/214
16
+
17
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/215
18
+
19
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v5.3.4...v5.3.5
20
+
3
21
  ### 5.3.4
4
22
 
5
23
  * fix(Queue Mode): handle OS signals and RSpec internal `wants_to_quit` and `rspec_is_quitting` states to stop consuming tests from the Queue API when the CI node is terminated
data/bin/rspec ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("rspec-core", "rspec")
@@ -59,18 +59,15 @@ module KnapsackPro
59
59
  request_hash.to_json
60
60
  end
61
61
 
62
- def test_suite_token
63
- KnapsackPro::Config::Env.test_suite_token
64
- end
65
-
66
62
  def json_headers
67
63
  {
68
64
  'Content-Type' => 'application/json',
69
65
  'Accept' => 'application/json',
70
66
  'KNAPSACK-PRO-CLIENT-NAME' => client_name,
71
67
  'KNAPSACK-PRO-CLIENT-VERSION' => KnapsackPro::VERSION,
72
- 'KNAPSACK-PRO-TEST-SUITE-TOKEN' => test_suite_token,
73
- }
68
+ 'KNAPSACK-PRO-TEST-SUITE-TOKEN' => KnapsackPro::Config::Env.test_suite_token,
69
+ 'KNAPSACK-PRO-CI-PROVIDER' => KnapsackPro::Config::Env.ci_provider,
70
+ }.compact
74
71
  end
75
72
 
76
73
  def client_name
@@ -34,6 +34,10 @@ module KnapsackPro
34
34
  def fixed_queue_split
35
35
  false
36
36
  end
37
+
38
+ def ci_provider
39
+ "AppVeyor"
40
+ end
37
41
  end
38
42
  end
39
43
  end
@@ -32,6 +32,21 @@ module KnapsackPro
32
32
  def fixed_queue_split
33
33
  true
34
34
  end
35
+
36
+ def ci_provider
37
+ return 'AWS CodeBuild' if ENV.key?('CODEBUILD_BUILD_ARN')
38
+ return 'Azure Pipelines' if ENV.key?('SYSTEM_TEAMFOUNDATIONCOLLECTIONURI')
39
+ return 'Bamboo' if ENV.key?('bamboo_planKey')
40
+ return 'Bitbucket Pipelines' if ENV.key?('BITBUCKET_COMMIT')
41
+ return 'Buddy.works' if ENV.key?('BUDDY')
42
+ return 'Drone.io' if ENV.key?('DRONE')
43
+ return 'Google Cloud Build' if ENV.key?('BUILDER_OUTPUT')
44
+ return 'Jenkins' if ENV.key?('JENKINS_URL')
45
+ return 'TeamCity' if ENV.key?('TEAMCITY_VERSION')
46
+ return 'Other' if KnapsackPro::Config::Env.ci?
47
+
48
+ nil
49
+ end
35
50
  end
36
51
  end
37
52
  end
@@ -41,6 +41,10 @@ module KnapsackPro
41
41
  def fixed_queue_split
42
42
  true
43
43
  end
44
+
45
+ def ci_provider
46
+ "Buildkite"
47
+ end
44
48
  end
45
49
  end
46
50
  end
@@ -37,6 +37,10 @@ module KnapsackPro
37
37
  def fixed_queue_split
38
38
  false
39
39
  end
40
+
41
+ def ci_provider
42
+ "CircleCI"
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -33,6 +33,10 @@ module KnapsackPro
33
33
  def fixed_queue_split
34
34
  false
35
35
  end
36
+
37
+ def ci_provider
38
+ "Cirrus CI"
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -34,6 +34,10 @@ module KnapsackPro
34
34
  def fixed_queue_split
35
35
  false
36
36
  end
37
+
38
+ def ci_provider
39
+ "Codefresh"
40
+ end
37
41
  end
38
42
  end
39
43
  end
@@ -33,6 +33,10 @@ module KnapsackPro
33
33
  def fixed_queue_split
34
34
  true
35
35
  end
36
+
37
+ def ci_provider
38
+ "Codeship"
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -49,6 +49,10 @@ module KnapsackPro
49
49
  def fixed_queue_split
50
50
  true
51
51
  end
52
+
53
+ def ci_provider
54
+ "GitHub Actions"
55
+ end
52
56
  end
53
57
  end
54
58
  end
@@ -45,6 +45,10 @@ module KnapsackPro
45
45
  def fixed_queue_split
46
46
  true
47
47
  end
48
+
49
+ def ci_provider
50
+ "Gitlab CI"
51
+ end
48
52
  end
49
53
  end
50
54
  end
@@ -33,6 +33,10 @@ module KnapsackPro
33
33
  def fixed_queue_split
34
34
  false
35
35
  end
36
+
37
+ def ci_provider
38
+ "Heroku CI"
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -34,6 +34,10 @@ module KnapsackPro
34
34
  def fixed_queue_split
35
35
  false
36
36
  end
37
+
38
+ def ci_provider
39
+ "Semaphore CI 1.0"
40
+ end
37
41
  end
38
42
  end
39
43
  end
@@ -38,6 +38,10 @@ module KnapsackPro
38
38
  def fixed_queue_split
39
39
  false
40
40
  end
41
+
42
+ def ci_provider
43
+ "Semaphore CI 2.0"
44
+ end
41
45
  end
42
46
  end
43
47
  end
@@ -25,6 +25,10 @@ module KnapsackPro
25
25
  def fixed_queue_split
26
26
  true
27
27
  end
28
+
29
+ def ci_provider
30
+ "Travis CI"
31
+ end
28
32
  end
29
33
  end
30
34
  end
@@ -269,6 +269,10 @@ module KnapsackPro
269
269
  detected || KnapsackPro::Config::CI::Base
270
270
  end
271
271
 
272
+ def ci_provider
273
+ detected_ci.new.ci_provider
274
+ end
275
+
272
276
  def log_level
273
277
  LOG_LEVELS[ENV['KNAPSACK_PRO_LOG_LEVEL'].to_s.downcase] || ::Logger::DEBUG
274
278
  end
@@ -62,11 +62,39 @@ module KnapsackPro
62
62
  unless most_recent_pending.empty?
63
63
  registered_output.puts('All pending tests on this CI node:')
64
64
  registered_output.puts(most_recent_pending)
65
+ registered_output.puts('')
65
66
  end
66
67
 
67
68
  unless most_recent_failures_summary.empty?
68
69
  registered_output.puts('All failed tests on this CI node:')
69
70
  registered_output.puts(most_recent_failures_summary)
71
+ registered_output.puts('')
72
+ end
73
+
74
+ registered_output.puts(most_recent_summary)
75
+ end
76
+
77
+ def self.print_exit_summary
78
+ registered_output.puts('Knapsack Pro Queue exited/aborted!')
79
+ registered_output.puts('')
80
+
81
+ unexecuted_test_files = KnapsackPro.tracker.unexecuted_test_files
82
+ unless unexecuted_test_files.empty?
83
+ registered_output.puts('Unexecuted tests on this CI node:')
84
+ registered_output.puts(unexecuted_test_files)
85
+ registered_output.puts('')
86
+ end
87
+
88
+ unless most_recent_pending.empty?
89
+ registered_output.puts('All pending tests on this CI node:')
90
+ registered_output.puts(most_recent_pending)
91
+ registered_output.puts('')
92
+ end
93
+
94
+ unless most_recent_failures_summary.empty?
95
+ registered_output.puts('All failed tests on this CI node:')
96
+ registered_output.puts(most_recent_failures_summary)
97
+ registered_output.puts('')
70
98
  end
71
99
 
72
100
  registered_output.puts(most_recent_summary)
@@ -92,35 +92,44 @@ module KnapsackPro
92
92
  options = ::RSpec::Core::ConfigurationOptions.new(cli_args)
93
93
  rspec_runner = ::RSpec::Core::Runner.new(options)
94
94
 
95
- exit_code = rspec_runner.run($stderr, $stdout)
96
- exitstatus = exit_code if exit_code != 0
97
-
98
- if rspec_runner.world.wants_to_quit
99
- KnapsackPro.logger.warn('RSpec wants to quit.')
100
- set_terminate_process
101
- end
102
- if rspec_runner.world.rspec_is_quitting
103
- KnapsackPro.logger.warn('RSpec is quitting.')
104
- set_terminate_process
95
+ begin
96
+ exit_code = rspec_runner.run($stderr, $stdout)
97
+ exitstatus = exit_code if exit_code != 0
98
+ rescue Exception => exception
99
+ KnapsackPro.logger.error("Having exception when running RSpec: #{exception.inspect}")
100
+ KnapsackPro::Formatters::RSpecQueueSummaryFormatter.print_exit_summary
101
+ KnapsackPro::Hooks::Queue.call_after_subset_queue
102
+ KnapsackPro::Hooks::Queue.call_after_queue
103
+ Kernel.exit(1)
104
+ raise
105
+ else
106
+ if rspec_runner.world.wants_to_quit
107
+ KnapsackPro.logger.warn('RSpec wants to quit.')
108
+ set_terminate_process
109
+ end
110
+ if rspec_runner.world.rspec_is_quitting
111
+ KnapsackPro.logger.warn('RSpec is quitting.')
112
+ set_terminate_process
113
+ end
114
+
115
+ printable_args = args_with_seed_option_added_when_viable(args, rspec_runner)
116
+ log_rspec_command(printable_args, test_file_paths, :subset_queue)
117
+
118
+ rspec_clear_examples
119
+
120
+ KnapsackPro::Hooks::Queue.call_after_subset_queue
121
+
122
+ KnapsackPro::Report.save_subset_queue_to_file
123
+
124
+ return {
125
+ status: :next,
126
+ runner: runner,
127
+ can_initialize_queue: false,
128
+ args: args,
129
+ exitstatus: exitstatus,
130
+ all_test_file_paths: all_test_file_paths,
131
+ }
105
132
  end
106
-
107
- printable_args = args_with_seed_option_added_when_viable(args, rspec_runner)
108
- log_rspec_command(printable_args, test_file_paths, :subset_queue)
109
-
110
- rspec_clear_examples
111
-
112
- KnapsackPro::Hooks::Queue.call_after_subset_queue
113
-
114
- KnapsackPro::Report.save_subset_queue_to_file
115
-
116
- return {
117
- status: :next,
118
- runner: runner,
119
- can_initialize_queue: false,
120
- args: args,
121
- exitstatus: exitstatus,
122
- all_test_file_paths: all_test_file_paths,
123
- }
124
133
  end
125
134
  end
126
135
 
@@ -68,6 +68,12 @@ module KnapsackPro
68
68
  @prerun_tests_loaded = true
69
69
  end
70
70
 
71
+ def unexecuted_test_files
72
+ @test_files_with_time.map do |path, hash|
73
+ path unless hash[:measured_time]
74
+ end.compact
75
+ end
76
+
71
77
  def to_a
72
78
  # When the test files are not loaded in the memory then load them from the disk.
73
79
  # Useful for the Regular Mode when the memory is not shared between tracker instances.
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '5.3.4'
2
+ VERSION = '5.4.0'
3
3
  end
@@ -289,6 +289,7 @@ describe KnapsackPro::Client::Connection do
289
289
  stub_const('ENV', {
290
290
  'KNAPSACK_PRO_ENDPOINT' => 'http://api.knapsackpro.test:3000',
291
291
  'KNAPSACK_PRO_TEST_SUITE_TOKEN' => test_suite_token,
292
+ 'GITHUB_ACTIONS' => 'true',
292
293
  })
293
294
  end
294
295
 
@@ -323,6 +324,7 @@ describe KnapsackPro::Client::Connection do
323
324
  'KNAPSACK-PRO-CLIENT-NAME' => 'knapsack_pro-ruby',
324
325
  'KNAPSACK-PRO-CLIENT-VERSION' => KnapsackPro::VERSION,
325
326
  'KNAPSACK-PRO-TEST-SUITE-TOKEN' => test_suite_token,
327
+ 'KNAPSACK-PRO-CI-PROVIDER' => 'GitHub Actions',
326
328
  }
327
329
  ).and_return(http_response)
328
330
  end
@@ -346,6 +348,7 @@ describe KnapsackPro::Client::Connection do
346
348
  'KNAPSACK-PRO-CLIENT-NAME' => 'knapsack_pro-ruby',
347
349
  'KNAPSACK-PRO-CLIENT-VERSION' => KnapsackPro::VERSION,
348
350
  'KNAPSACK-PRO-TEST-SUITE-TOKEN' => test_suite_token,
351
+ 'KNAPSACK-PRO-CI-PROVIDER' => 'GitHub Actions',
349
352
  }
350
353
  ).and_return(http_response)
351
354
  end
@@ -368,6 +371,7 @@ describe KnapsackPro::Client::Connection do
368
371
  'KNAPSACK-PRO-CLIENT-NAME' => 'knapsack_pro-ruby',
369
372
  'KNAPSACK-PRO-CLIENT-VERSION' => KnapsackPro::VERSION,
370
373
  'KNAPSACK-PRO-TEST-SUITE-TOKEN' => test_suite_token,
374
+ 'KNAPSACK-PRO-CI-PROVIDER' => 'GitHub Actions',
371
375
  }
372
376
  ).and_return(http_response)
373
377
  end
@@ -391,6 +395,7 @@ describe KnapsackPro::Client::Connection do
391
395
  'KNAPSACK-PRO-CLIENT-NAME' => 'knapsack_pro-ruby',
392
396
  'KNAPSACK-PRO-CLIENT-VERSION' => KnapsackPro::VERSION,
393
397
  'KNAPSACK-PRO-TEST-SUITE-TOKEN' => test_suite_token,
398
+ 'KNAPSACK-PRO-CI-PROVIDER' => 'GitHub Actions',
394
399
  }
395
400
  ).and_return(http_response)
396
401
  end
@@ -676,7 +676,7 @@ describe KnapsackPro::Config::Env do
676
676
  ['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }],
677
677
  ['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }],
678
678
  ['Travis CI', { 'TRAVIS' => 'true' }],
679
- ['Unsupported', {}],
679
+ ['Unsupported CI', {}],
680
680
  ].each do |ci, env|
681
681
  it "on #{ci} it is false" do
682
682
  logger = instance_double(Logger)
@@ -704,7 +704,7 @@ describe KnapsackPro::Config::Env do
704
704
  ['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }],
705
705
  ['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }],
706
706
  ['Travis CI', { 'TRAVIS' => 'true' }],
707
- ['Unsupported', {}],
707
+ ['Unsupported CI', {}],
708
708
  ].each do |ci, env|
709
709
  it "on #{ci} it is true" do
710
710
  logger = instance_double(Logger)
@@ -733,7 +733,7 @@ describe KnapsackPro::Config::Env do
733
733
  ['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }, false],
734
734
  ['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }, false],
735
735
  ['Travis CI', { 'TRAVIS' => 'true' }, true],
736
- ['Unsupported', {}, true],
736
+ ['Unsupported CI', {}, true],
737
737
  ].each do |ci, env, expected|
738
738
  it "on #{ci} it is #{expected}" do
739
739
  logger = instance_double(Logger)
@@ -1032,7 +1032,7 @@ describe KnapsackPro::Config::Env do
1032
1032
  ['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }, KnapsackPro::Config::CI::Semaphore],
1033
1033
  ['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }, KnapsackPro::Config::CI::Semaphore2],
1034
1034
  ['Travis CI', { 'TRAVIS' => 'true' }, KnapsackPro::Config::CI::Travis],
1035
- ['Unsupported', {}, KnapsackPro::Config::CI::Base],
1035
+ ['Unsupported CI', {}, KnapsackPro::Config::CI::Base],
1036
1036
  ].each do |ci, env, expected|
1037
1037
  it "detects #{ci}" do
1038
1038
  stub_const("ENV", env)
@@ -1046,7 +1046,7 @@ describe KnapsackPro::Config::Env do
1046
1046
  [
1047
1047
  ['CI from env', { 'CI' => 'True' }, true],
1048
1048
  ['Travis CI', { 'TRAVIS' => 'true' }, true],
1049
- ['Unsupported', {}, false],
1049
+ ['missing CI from ENV or development', {}, false],
1050
1050
  ].each do |ci, env, expected|
1051
1051
  it "detects #{ci}" do
1052
1052
  stub_const("ENV", env)
@@ -1055,4 +1055,38 @@ describe KnapsackPro::Config::Env do
1055
1055
  end
1056
1056
  end
1057
1057
  end
1058
+
1059
+ describe '.ci_provider' do
1060
+ [
1061
+ ['AppVeyor', { 'APPVEYOR' => '123' }],
1062
+ ['Azure Pipelines', { 'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI' => '123' }],
1063
+ ['AWS CodeBuild', { 'CODEBUILD_BUILD_ARN' => '123' }],
1064
+ ['Bamboo', { 'bamboo_planKey' => '123' }],
1065
+ ['Bitbucket Pipelines', { 'BITBUCKET_COMMIT' => '123' }],
1066
+ ['Buddy.works', { 'BUDDY' => 'true' }],
1067
+ ['Buildkite', { 'BUILDKITE' => 'true' }],
1068
+ ['CircleCI', { 'CIRCLECI' => 'true' }],
1069
+ ['Cirrus CI', { 'CIRRUS_CI' => 'true' }],
1070
+ ['Codefresh', { 'CF_BUILD_ID' => '123' }],
1071
+ ['Codeship', { 'CI_NAME' => 'codeship' }],
1072
+ ['Drone.io', { 'DRONE' => 'true' }],
1073
+ ['GitHub Actions', { 'GITHUB_ACTIONS' => 'true' }],
1074
+ ['Gitlab CI', { 'GITLAB_CI' => 'true' }],
1075
+ ['Google Cloud Build', { 'BUILDER_OUTPUT' => '123' }],
1076
+ ['Heroku CI', { 'HEROKU_TEST_RUN_ID' => '123' }],
1077
+ ['Jenkins', { 'JENKINS_URL' => '123' }],
1078
+ ['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }],
1079
+ ['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }],
1080
+ ['TeamCity', { 'TEAMCITY_VERSION' => '123' }],
1081
+ ['Travis CI', { 'TRAVIS' => 'true' }],
1082
+ ['Other', { 'CI' => 'true'}],
1083
+ [nil, {}],
1084
+ ].each do |ci, env|
1085
+ it "detects #{ci} name" do
1086
+ stub_const("ENV", env)
1087
+
1088
+ expect(described_class.ci_provider).to eq(ci)
1089
+ end
1090
+ end
1091
+ end
1058
1092
  end
@@ -212,126 +212,183 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
212
212
  double(world: double(wants_to_quit: rspec_wants_to_quit, rspec_is_quitting: rspec_is_quitting))
213
213
  end
214
214
 
215
- before do
216
- subset_queue_id = 'fake-subset-queue-id'
217
- expect(KnapsackPro::Config::EnvGenerator).to receive(:set_subset_queue_id).and_return(subset_queue_id)
215
+ context 'having no exception when running RSpec' do
216
+ before do
217
+ subset_queue_id = 'fake-subset-queue-id'
218
+ expect(KnapsackPro::Config::EnvGenerator).to receive(:set_subset_queue_id).and_return(subset_queue_id)
218
219
 
219
- expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_SUBSET_QUEUE_ID', subset_queue_id)
220
+ expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_SUBSET_QUEUE_ID', subset_queue_id)
220
221
 
221
- tracker = instance_double(KnapsackPro::Tracker)
222
- expect(KnapsackPro).to receive(:tracker).twice.and_return(tracker)
223
- expect(tracker).to receive(:reset!)
224
- expect(tracker).to receive(:set_prerun_tests).with(test_file_paths)
222
+ tracker = instance_double(KnapsackPro::Tracker)
223
+ expect(KnapsackPro).to receive(:tracker).twice.and_return(tracker)
224
+ expect(tracker).to receive(:reset!)
225
+ expect(tracker).to receive(:set_prerun_tests).with(test_file_paths)
225
226
 
226
- expect(described_class).to receive(:ensure_spec_opts_have_rspec_queue_summary_formatter)
227
- options = double
228
- expect(RSpec::Core::ConfigurationOptions).to receive(:new).with([
229
- '--no-color',
230
- '--default-path', 'fake-test-dir',
231
- 'a_spec.rb', 'b_spec.rb',
232
- ]).and_return(options)
227
+ expect(described_class).to receive(:ensure_spec_opts_have_rspec_queue_summary_formatter)
228
+ options = double
229
+ expect(RSpec::Core::ConfigurationOptions).to receive(:new).with([
230
+ '--no-color',
231
+ '--default-path', 'fake-test-dir',
232
+ 'a_spec.rb', 'b_spec.rb',
233
+ ]).and_return(options)
233
234
 
234
- expect(RSpec::Core::Runner).to receive(:new).with(options).and_return(rspec_core_runner)
235
- expect(rspec_core_runner).to receive(:run).with($stderr, $stdout).and_return(exit_code)
235
+ expect(RSpec::Core::Runner).to receive(:new).with(options).and_return(rspec_core_runner)
236
+ expect(rspec_core_runner).to receive(:run).with($stderr, $stdout).and_return(exit_code)
236
237
 
237
- expect(described_class).to receive(:rspec_clear_examples)
238
+ expect(described_class).to receive(:rspec_clear_examples)
238
239
 
239
- expect(KnapsackPro::Hooks::Queue).to receive(:call_before_subset_queue)
240
+ expect(KnapsackPro::Hooks::Queue).to receive(:call_before_subset_queue)
240
241
 
241
- expect(KnapsackPro::Hooks::Queue).to receive(:call_after_subset_queue)
242
+ expect(KnapsackPro::Hooks::Queue).to receive(:call_after_subset_queue)
242
243
 
243
- expect(KnapsackPro::Report).to receive(:save_subset_queue_to_file)
244
+ expect(KnapsackPro::Report).to receive(:save_subset_queue_to_file)
244
245
 
245
- configuration = double
246
- expect(rspec_core_runner).to receive(:configuration).twice.and_return(configuration)
247
- expect(configuration).to receive(:seed_used?).and_return(true)
248
- expect(configuration).to receive(:seed).and_return(rspec_seed)
246
+ configuration = double
247
+ expect(rspec_core_runner).to receive(:configuration).twice.and_return(configuration)
248
+ expect(configuration).to receive(:seed_used?).and_return(true)
249
+ expect(configuration).to receive(:seed).and_return(rspec_seed)
249
250
 
250
- expect(KnapsackPro).to receive(:logger).at_least(2).and_return(logger)
251
- expect(logger).to receive(:info)
252
- .with("To retry the last batch of tests fetched from the API Queue, please run the following command on your machine:")
253
- expect(logger).to receive(:info).with(/#{args.join(' ')} --seed #{rspec_seed}/)
254
- end
251
+ expect(KnapsackPro).to receive(:logger).at_least(2).and_return(logger)
252
+ expect(logger).to receive(:info)
253
+ .with("To retry the last batch of tests fetched from the API Queue, please run the following command on your machine:")
254
+ expect(logger).to receive(:info).with(/#{args.join(' ')} --seed #{rspec_seed}/)
255
+ end
255
256
 
256
- context 'when the exit code is zero' do
257
- let(:exit_code) { 0 }
257
+ context 'when the exit code is zero' do
258
+ let(:exit_code) { 0 }
258
259
 
259
- it do
260
- expect(subject).to eq({
261
- status: :next,
262
- runner: runner,
263
- can_initialize_queue: false,
264
- args: args,
265
- exitstatus: exitstatus,
266
- all_test_file_paths: test_file_paths,
267
- })
260
+ it do
261
+ expect(subject).to eq({
262
+ status: :next,
263
+ runner: runner,
264
+ can_initialize_queue: false,
265
+ args: args,
266
+ exitstatus: exitstatus,
267
+ all_test_file_paths: test_file_paths,
268
+ })
269
+ end
268
270
  end
269
- end
270
271
 
271
- context 'when the exit code is not zero' do
272
- let(:exit_code) { double }
272
+ context 'when the exit code is not zero' do
273
+ let(:exit_code) { double }
273
274
 
274
- it do
275
- expect(subject).to eq({
276
- status: :next,
277
- runner: runner,
278
- can_initialize_queue: false,
279
- args: args,
280
- exitstatus: exit_code,
281
- all_test_file_paths: test_file_paths,
282
- })
275
+ it do
276
+ expect(subject).to eq({
277
+ status: :next,
278
+ runner: runner,
279
+ can_initialize_queue: false,
280
+ args: args,
281
+ exitstatus: exit_code,
282
+ all_test_file_paths: test_file_paths,
283
+ })
284
+ end
283
285
  end
284
- end
285
286
 
286
- context 'when RSpec wants to quit' do
287
- let(:exit_code) { 0 }
288
- let(:rspec_wants_to_quit) { true }
287
+ context 'when RSpec wants to quit' do
288
+ let(:exit_code) { 0 }
289
+ let(:rspec_wants_to_quit) { true }
290
+
291
+ after do
292
+ described_class.class_variable_set(:@@terminate_process, false)
293
+ end
294
+
295
+ it 'terminates the process' do
296
+ expect(logger).to receive(:warn).with('RSpec wants to quit.')
289
297
 
290
- after do
291
- described_class.class_variable_set(:@@terminate_process, false)
298
+ expect(described_class.class_variable_get(:@@terminate_process)).to be false
299
+
300
+ expect(subject).to eq({
301
+ status: :next,
302
+ runner: runner,
303
+ can_initialize_queue: false,
304
+ args: args,
305
+ exitstatus: exitstatus,
306
+ all_test_file_paths: test_file_paths,
307
+ })
308
+
309
+ expect(described_class.class_variable_get(:@@terminate_process)).to be true
310
+ end
292
311
  end
293
312
 
294
- it 'terminates the process' do
295
- expect(logger).to receive(:warn).with('RSpec wants to quit.')
313
+ context 'when RSpec is quitting' do
314
+ let(:exit_code) { 0 }
315
+ let(:rspec_is_quitting) { true }
296
316
 
297
- expect(described_class.class_variable_get(:@@terminate_process)).to be false
317
+ after do
318
+ described_class.class_variable_set(:@@terminate_process, false)
319
+ end
298
320
 
299
- expect(subject).to eq({
300
- status: :next,
301
- runner: runner,
302
- can_initialize_queue: false,
303
- args: args,
304
- exitstatus: exitstatus,
305
- all_test_file_paths: test_file_paths,
306
- })
321
+ it 'terminates the process' do
322
+ expect(logger).to receive(:warn).with('RSpec is quitting.')
307
323
 
308
- expect(described_class.class_variable_get(:@@terminate_process)).to be true
324
+ expect(described_class.class_variable_get(:@@terminate_process)).to be false
325
+
326
+ expect(subject).to eq({
327
+ status: :next,
328
+ runner: runner,
329
+ can_initialize_queue: false,
330
+ args: args,
331
+ exitstatus: exitstatus,
332
+ all_test_file_paths: test_file_paths,
333
+ })
334
+
335
+ expect(described_class.class_variable_get(:@@terminate_process)).to be true
336
+ end
309
337
  end
310
338
  end
311
339
 
312
- context 'when RSpec is quitting' do
313
- let(:exit_code) { 0 }
314
- let(:rspec_is_quitting) { true }
315
-
316
- after do
317
- described_class.class_variable_set(:@@terminate_process, false)
340
+ context 'having exception when running RSpec' do
341
+ before do
342
+ subset_queue_id = 'fake-subset-queue-id'
343
+ expect(KnapsackPro::Config::EnvGenerator).to receive(:set_subset_queue_id).and_return(subset_queue_id)
344
+
345
+ expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_SUBSET_QUEUE_ID', subset_queue_id)
346
+
347
+ tracker = instance_double(KnapsackPro::Tracker)
348
+ expect(KnapsackPro).to receive(:tracker).twice.and_return(tracker)
349
+ expect(tracker).to receive(:reset!)
350
+ expect(tracker).to receive(:set_prerun_tests).with(test_file_paths)
351
+
352
+ expect(described_class).to receive(:ensure_spec_opts_have_rspec_queue_summary_formatter)
353
+ options = double
354
+ expect(RSpec::Core::ConfigurationOptions).to receive(:new).with([
355
+ '--no-color',
356
+ '--default-path', 'fake-test-dir',
357
+ 'a_spec.rb', 'b_spec.rb',
358
+ ]).and_return(options)
359
+
360
+ rspec_core_runner = double
361
+ expect(RSpec::Core::Runner).to receive(:new).with(options).and_return(rspec_core_runner)
362
+ expect(rspec_core_runner).to receive(:run).with($stderr, $stdout).and_raise SystemExit
363
+ expect(KnapsackPro::Hooks::Queue).to receive(:call_before_subset_queue)
364
+ allow(KnapsackPro::Report).to receive(:save_subset_queue_to_file)
365
+ allow(KnapsackPro::Hooks::Queue).to receive(:call_after_subset_queue)
366
+ allow(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
367
+ allow(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_exit_summary)
368
+ expect(Kernel).to receive(:exit).with(1)
318
369
  end
319
370
 
320
- it 'terminates the process' do
321
- expect(logger).to receive(:warn).with('RSpec is quitting.')
371
+ it 'does not call #save_subset_queue_to_file or #rspec_clear_examples' do
372
+ expect(described_class).not_to receive(:rspec_clear_examples)
373
+ expect(KnapsackPro::Report).not_to receive(:save_subset_queue_to_file)
374
+ expect { subject }.to raise_error SystemExit
375
+ end
322
376
 
323
- expect(described_class.class_variable_get(:@@terminate_process)).to be false
377
+ it 'logs the exception' do
378
+ expect(KnapsackPro).to receive(:logger).once.and_return(logger)
379
+ expect(logger).to receive(:error).with("Having exception when running RSpec: #<SystemExit: SystemExit>")
380
+ expect { subject }.to raise_error SystemExit
381
+ end
324
382
 
325
- expect(subject).to eq({
326
- status: :next,
327
- runner: runner,
328
- can_initialize_queue: false,
329
- args: args,
330
- exitstatus: exitstatus,
331
- all_test_file_paths: test_file_paths,
332
- })
383
+ it 'calls #print_exit_summary' do
384
+ expect(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_exit_summary)
385
+ expect { subject }.to raise_error SystemExit
386
+ end
333
387
 
334
- expect(described_class.class_variable_get(:@@terminate_process)).to be true
388
+ it 'calls #call_after_subset_queue and #call_after_queue' do
389
+ expect(KnapsackPro::Hooks::Queue).to receive(:call_after_subset_queue)
390
+ expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
391
+ expect { subject }.to raise_error SystemExit
335
392
  end
336
393
  end
337
394
  end
@@ -185,4 +185,21 @@ describe KnapsackPro::Tracker do
185
185
  expect(tracker.prerun_tests_loaded).to be false
186
186
  end
187
187
  end
188
+
189
+
190
+ describe '#unexecuted_test_files' do
191
+ before do
192
+ tracker.set_prerun_tests(['a_spec.rb', 'b_spec.rb', 'c_spec.rb'])
193
+
194
+ # measure execution time for b_spec.rb
195
+ tracker.current_test_path = 'b_spec.rb'
196
+ tracker.start_timer
197
+ sleep 0.1
198
+ tracker.stop_timer
199
+ end
200
+
201
+ it 'returns test files without measured time' do
202
+ expect(tracker.unexecuted_test_files).to eq(['a_spec.rb', 'c_spec.rb'])
203
+ end
204
+ end
188
205
  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: 5.3.4
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-26 00:00:00.000000000 Z
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -186,6 +186,7 @@ email:
186
186
  - arturtrzop@gmail.com
187
187
  executables:
188
188
  - knapsack_pro
189
+ - rspec
189
190
  extensions: []
190
191
  extra_rdoc_files: []
191
192
  files:
@@ -201,6 +202,7 @@ files:
201
202
  - README.md
202
203
  - Rakefile
203
204
  - bin/knapsack_pro
205
+ - bin/rspec
204
206
  - knapsack_pro.gemspec
205
207
  - lib/knapsack_pro.rb
206
208
  - lib/knapsack_pro/adapters/base_adapter.rb