knapsack_pro 1.22.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -0
- data/README.md +16 -0
- data/lib/knapsack_pro/adapters/cucumber_adapter.rb +1 -1
- data/lib/knapsack_pro/adapters/minitest_adapter.rb +3 -3
- data/lib/knapsack_pro/adapters/rspec_adapter.rb +1 -1
- data/lib/knapsack_pro/adapters/test_unit_adapter.rb +2 -2
- data/lib/knapsack_pro/base_allocator_builder.rb +7 -2
- data/lib/knapsack_pro/config/ci/github_actions.rb +3 -2
- data/lib/knapsack_pro/config/env.rb +4 -0
- data/lib/knapsack_pro/formatters/rspec_json_formatter.rb +2 -2
- data/lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb +1 -1
- data/lib/knapsack_pro/formatters/rspec_queue_summary_formatter.rb +2 -2
- data/lib/knapsack_pro/hooks/queue.rb +31 -22
- data/lib/knapsack_pro/runners/cucumber_runner.rb +1 -1
- data/lib/knapsack_pro/runners/queue/minitest_runner.rb +2 -2
- data/lib/knapsack_pro/runners/queue/rspec_runner.rb +12 -12
- data/lib/knapsack_pro/runners/rspec_runner.rb +1 -1
- data/lib/knapsack_pro/runners/test_unit_runner.rb +1 -1
- data/lib/knapsack_pro/test_case_detectors/rspec_test_example_detector.rb +3 -3
- data/lib/knapsack_pro/version.rb +1 -1
- data/spec/knapsack_pro/config/ci/github_actions_spec.rb +8 -1
- data/spec/knapsack_pro/config/env_spec.rb +14 -0
- data/spec/knapsack_pro/hooks/queue_spec.rb +49 -13
- data/spec/knapsack_pro/runners/queue/rspec_runner_spec.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b399cf5cff114341276acbcc1c9c372ff4bfb51ffc05a5ee5b59cf531dc64feb
|
4
|
+
data.tar.gz: aed0dea9791ab8589c63192e53b3f64c2a071f690553bc0d450be61d20b51b1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d44d7d00c68d618d7ec41b764b28a8bcd7e5f2c62329d7246f2ee760f0d956ce7f1ffbbf6e8fae2adedf3cbd62d83a255f0b89a1dff9c8cc216d42cd11a89603
|
7
|
+
data.tar.gz: 403cbc599ff70473aa07ae92abb73016a942c3ed21a2bbcb376ade1e8d0fe62e1ea64677fd6527c5a2b8822bd65fa7c6139ffb6c0850f273b795303974724bab
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,51 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### 2.2.0
|
4
|
+
|
5
|
+
* Allow defining Queue Mode hooks multiple times (`KnapsackPro::Hooks::Queue.before_queue`, `KnapsackPro::Hooks::Queue.after_subset_queue`, `KnapsackPro::Hooks::Queue.after_queue`)
|
6
|
+
|
7
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/122
|
8
|
+
|
9
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.1.1...v2.2.0
|
10
|
+
|
11
|
+
### 2.1.1
|
12
|
+
|
13
|
+
* Explicitly call root test runner class to avoid a confusing error when test runner gem is not loaded
|
14
|
+
|
15
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/120
|
16
|
+
|
17
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.1.0...v2.1.1
|
18
|
+
|
19
|
+
### 2.1.0
|
20
|
+
|
21
|
+
* Add `KNAPSACK_PRO_RSPEC_TEST_EXAMPLE_DETECTOR_PREFIX` to customize prefix for generating test examples report when using RSpec split by test examples
|
22
|
+
|
23
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/118
|
24
|
+
|
25
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.0.0...v2.1.0
|
26
|
+
|
27
|
+
### 2.0.0
|
28
|
+
|
29
|
+
* Add support for CI build ID for Github Actions
|
30
|
+
|
31
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/116
|
32
|
+
|
33
|
+
__Migration path for Github Actions users - required__
|
34
|
+
|
35
|
+
If you use Github Actions and Knapsack Pro Queue Mode then you must set in Github Actions environment variable: `KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true`. Thanks to that when you retry CI build then tests will run based on previously recorded tests. This solves problem mentioned in the [PR](https://github.com/KnapsackPro/knapsack_pro-ruby/pull/116).
|
36
|
+
|
37
|
+
__Migration path for other users__ - just update `knapsack_pro` gem. Nothing to change in your code :)
|
38
|
+
|
39
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v1.22.3...v2.0.0
|
40
|
+
|
41
|
+
### 1.22.3
|
42
|
+
|
43
|
+
* Support for non-delimited formatting params of RSpec like `-fMyCustomFormatter`
|
44
|
+
|
45
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/115
|
46
|
+
|
47
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v1.22.2...v1.22.3
|
48
|
+
|
3
49
|
### 1.22.2
|
4
50
|
|
5
51
|
* Log when next retry request to Knapsack Pro API happens before starting Fallback Mode
|
data/README.md
CHANGED
@@ -84,6 +84,7 @@ We keep this old FAQ in README to not break old links spread across the web. You
|
|
84
84
|
- [Supported test runners in queue mode](#supported-test-runners-in-queue-mode)
|
85
85
|
- [Split test files by test cases](#split-test-files-by-test-cases)
|
86
86
|
- [RSpec split test files by test examples (by individual `it`s)](#rspec-split-test-files-by-test-examples-by-individual-its)
|
87
|
+
- [Why I see error: Don't know how to build task 'knapsack_pro:rspec_test_example_detector'?](#why-i-see-error-dont-know-how-to-build-task-knapsack_prorspec_test_example_detector)
|
87
88
|
- [How to manually define a list of slow test files to be split by test cases](#how-to-manually-define-a-list-of-slow-test-files-to-be-split-by-test-cases)
|
88
89
|
- [Extra configuration for CI server](#extra-configuration-for-ci-server)
|
89
90
|
- [Info about ENV variables](#info-about-env-variables)
|
@@ -618,6 +619,16 @@ KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES=true
|
|
618
619
|
|
619
620
|
Thanks to that your CI build speed can be faster. We recommend using this feature with [Queue Mode](https://youtu.be/hUEB1XDKEFY) to ensure parallel CI nodes finish work at a similar time which gives you the shortest CI build time.
|
620
621
|
|
622
|
+
#### Why I see error: Don't know how to build task 'knapsack_pro:rspec_test_example_detector'?
|
623
|
+
|
624
|
+
If you will see error like:
|
625
|
+
|
626
|
+
```
|
627
|
+
Don't know how to build task 'knapsack_pro:rspec_test_example_detector' (See the list of available tasks with `rake --tasks`)
|
628
|
+
```
|
629
|
+
|
630
|
+
It probably means bundler can't find the rake task. You can try to remove the default prefix `bundle exec` used by knapsack_pro gem by setting `KNAPSACK_PRO_RSPEC_TEST_EXAMPLE_DETECTOR_PREFIX=""`.
|
631
|
+
|
621
632
|
### How to manually define a list of slow test files to be split by test cases
|
622
633
|
|
623
634
|
If you don't want to rely on a list of test files from Knapsack Pro API to determine slow test files that should be split by test cases then you can define your own list of slow test files.
|
@@ -1639,6 +1650,9 @@ jobs:
|
|
1639
1650
|
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }}
|
1640
1651
|
KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
|
1641
1652
|
KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
|
1653
|
+
# if you use Knapsack Pro Queue Mode you must set below env variable
|
1654
|
+
# to be able to retry CI build and run previously recorded tests
|
1655
|
+
KNAPSACK_PRO_FIXED_QUEUE_SPLIT: true
|
1642
1656
|
run: |
|
1643
1657
|
# run tests in Knapsack Pro Regular Mode
|
1644
1658
|
bundle exec rake knapsack_pro:rspec
|
@@ -2723,6 +2737,8 @@ end
|
|
2723
2737
|
|
2724
2738
|
#### What hooks are supported in Queue Mode?
|
2725
2739
|
|
2740
|
+
Note: Each hook type can be defined multiple times. For instance, if you define `KnapsackPro::Hooks::Queue.before_queue` twice then both block of code will be called when running your tests.
|
2741
|
+
|
2726
2742
|
* RSpec in knapsack_pro Queue Mode supports hooks:
|
2727
2743
|
|
2728
2744
|
```ruby
|
@@ -85,10 +85,10 @@ module KnapsackPro
|
|
85
85
|
private
|
86
86
|
|
87
87
|
def add_post_run_callback(&block)
|
88
|
-
if Minitest.respond_to?(:after_run)
|
89
|
-
Minitest.after_run { block.call }
|
88
|
+
if ::Minitest.respond_to?(:after_run)
|
89
|
+
::Minitest.after_run { block.call }
|
90
90
|
else
|
91
|
-
Minitest::Unit.after_tests { block.call }
|
91
|
+
::Minitest::Unit.after_tests { block.call }
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
@@ -4,7 +4,7 @@ module KnapsackPro
|
|
4
4
|
TEST_DIR_PATTERN = 'spec/**{,/*/**}/*_spec.rb'
|
5
5
|
|
6
6
|
def self.test_path(example_group)
|
7
|
-
if defined?(Turnip) && Turnip::VERSION.to_i < 2
|
7
|
+
if defined?(::Turnip) && ::Turnip::VERSION.to_i < 2
|
8
8
|
unless example_group[:turnip]
|
9
9
|
until example_group[:parent_example_group].nil?
|
10
10
|
example_group = example_group[:parent_example_group]
|
@@ -42,7 +42,7 @@ module KnapsackPro
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def bind_time_tracker
|
45
|
-
Test::Unit::TestSuite.send(:prepend, BindTimeTrackerTestUnitPlugin)
|
45
|
+
::Test::Unit::TestSuite.send(:prepend, BindTimeTrackerTestUnitPlugin)
|
46
46
|
|
47
47
|
add_post_run_callback do
|
48
48
|
KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time)
|
@@ -63,7 +63,7 @@ module KnapsackPro
|
|
63
63
|
private
|
64
64
|
|
65
65
|
def add_post_run_callback(&block)
|
66
|
-
Test::Unit.at_exit do
|
66
|
+
::Test::Unit.at_exit do
|
67
67
|
block.call
|
68
68
|
end
|
69
69
|
end
|
@@ -34,7 +34,7 @@ module KnapsackPro
|
|
34
34
|
test_files_to_run = all_test_files_to_run
|
35
35
|
|
36
36
|
if adapter_class == KnapsackPro::Adapters::RSpecAdapter && KnapsackPro::Config::Env.rspec_split_by_test_examples?
|
37
|
-
unless Gem::Version.new(RSpec::Core::Version::STRING) >= Gem::Version.new('3.3.0')
|
37
|
+
unless Gem::Version.new(::RSpec::Core::Version::STRING) >= Gem::Version.new('3.3.0')
|
38
38
|
raise 'RSpec >= 3.3.0 is required to split test files by test examples. Learn more: https://github.com/KnapsackPro/knapsack_pro-ruby#split-test-files-by-test-cases'
|
39
39
|
end
|
40
40
|
|
@@ -43,7 +43,12 @@ module KnapsackPro
|
|
43
43
|
KnapsackPro.logger.info("Generating RSpec test examples JSON report for slow test files to prepare it to be split by test examples (by individual 'it's. Thanks to that a single slow test file can be split across parallel CI nodes). Analyzing #{slow_test_files.size} slow test files.")
|
44
44
|
|
45
45
|
# generate RSpec JSON report in separate process to not pollute RSpec state
|
46
|
-
cmd =
|
46
|
+
cmd = [
|
47
|
+
'RACK_ENV=test',
|
48
|
+
'RAILS_ENV=test',
|
49
|
+
KnapsackPro::Config::Env.rspec_test_example_detector_prefix,
|
50
|
+
'rake knapsack_pro:rspec_test_example_detector',
|
51
|
+
].join(' ')
|
47
52
|
unless Kernel.system(cmd)
|
48
53
|
raise "Could not generate JSON report for RSpec. Rake task failed when running #{cmd}"
|
49
54
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# https://help.github.com/en/
|
1
|
+
# https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
|
2
2
|
module KnapsackPro
|
3
3
|
module Config
|
4
4
|
module CI
|
@@ -12,7 +12,8 @@ module KnapsackPro
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def node_build_id
|
15
|
-
# not
|
15
|
+
# A unique number for each run within a repository. This number does not change if you re-run the workflow run.
|
16
|
+
ENV['GITHUB_RUN_ID']
|
16
17
|
end
|
17
18
|
|
18
19
|
def commit_hash
|
@@ -179,6 +179,10 @@ module KnapsackPro
|
|
179
179
|
rspec_split_by_test_examples.to_s == 'true'
|
180
180
|
end
|
181
181
|
|
182
|
+
def rspec_test_example_detector_prefix
|
183
|
+
ENV.fetch('KNAPSACK_PRO_RSPEC_TEST_EXAMPLE_DETECTOR_PREFIX', 'bundle exec')
|
184
|
+
end
|
185
|
+
|
182
186
|
def test_suite_token
|
183
187
|
env_name = 'KNAPSACK_PRO_TEST_SUITE_TOKEN'
|
184
188
|
ENV[env_name] || raise("Missing environment variable #{env_name}. You should set environment variable like #{env_name}_RSPEC (note there is suffix _RSPEC at the end). knapsack_pro gem will set #{env_name} based on #{env_name}_RSPEC value. If you use other test runner than RSpec then use proper suffix.")
|
@@ -3,8 +3,8 @@ RSpec::Support.require_rspec_core('formatters/json_formatter')
|
|
3
3
|
# based on https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/json_formatter.rb
|
4
4
|
module KnapsackPro
|
5
5
|
module Formatters
|
6
|
-
class RSpecJsonFormatter < RSpec::Core::Formatters::JsonFormatter
|
7
|
-
RSpec::Core::Formatters.register self
|
6
|
+
class RSpecJsonFormatter < ::RSpec::Core::Formatters::JsonFormatter
|
7
|
+
::RSpec::Core::Formatters.register self
|
8
8
|
|
9
9
|
private
|
10
10
|
|
@@ -5,7 +5,7 @@ module KnapsackPro
|
|
5
5
|
module RSpecQueueProfileFormatterExtension
|
6
6
|
def self.print_summary
|
7
7
|
return unless KnapsackPro::Config::Env.modify_default_rspec_formatters?
|
8
|
-
RSpec::Core::Formatters::ProfileFormatter.print_profile_summary
|
8
|
+
::RSpec::Core::Formatters::ProfileFormatter.print_profile_summary
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(output)
|
@@ -9,8 +9,8 @@ module KnapsackPro
|
|
9
9
|
def dump_summary(summary); end
|
10
10
|
end
|
11
11
|
|
12
|
-
class RSpecQueueSummaryFormatter < RSpec::Core::Formatters::BaseFormatter
|
13
|
-
RSpec::Core::Formatters.register self, :dump_summary, :dump_failures, :dump_pending
|
12
|
+
class RSpecQueueSummaryFormatter < ::RSpec::Core::Formatters::BaseFormatter
|
13
|
+
::RSpec::Core::Formatters.register self, :dump_summary, :dump_failures, :dump_pending
|
14
14
|
|
15
15
|
def self.registered_output=(output)
|
16
16
|
@registered_output = {
|
@@ -2,54 +2,63 @@ module KnapsackPro
|
|
2
2
|
module Hooks
|
3
3
|
class Queue
|
4
4
|
class << self
|
5
|
-
attr_reader :
|
6
|
-
:
|
7
|
-
:
|
5
|
+
attr_reader :before_queue_store,
|
6
|
+
:after_subset_queue_store,
|
7
|
+
:after_queue_store
|
8
8
|
|
9
9
|
def reset_before_queue
|
10
|
-
@
|
10
|
+
@before_queue_store = nil
|
11
11
|
end
|
12
12
|
|
13
13
|
def reset_after_subset_queue
|
14
|
-
@
|
14
|
+
@after_subset_queue_store = nil
|
15
15
|
end
|
16
16
|
|
17
17
|
def reset_after_queue
|
18
|
-
@
|
18
|
+
@after_queue_store = nil
|
19
19
|
end
|
20
20
|
|
21
21
|
def before_queue(&block)
|
22
|
-
@
|
22
|
+
@before_queue_store ||= []
|
23
|
+
@before_queue_store << block
|
23
24
|
end
|
24
25
|
|
25
26
|
def after_subset_queue(&block)
|
26
|
-
@
|
27
|
+
@after_subset_queue_store ||= []
|
28
|
+
@after_subset_queue_store << block
|
27
29
|
end
|
28
30
|
|
29
31
|
def after_queue(&block)
|
30
|
-
@
|
32
|
+
@after_queue_store ||= []
|
33
|
+
@after_queue_store << block
|
31
34
|
end
|
32
35
|
|
33
36
|
def call_before_queue
|
34
|
-
return unless
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
return unless before_queue_store
|
38
|
+
before_queue_store.each do |block|
|
39
|
+
block.call(
|
40
|
+
KnapsackPro::Config::Env.queue_id
|
41
|
+
)
|
42
|
+
end
|
38
43
|
end
|
39
44
|
|
40
45
|
def call_after_subset_queue
|
41
|
-
return unless
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
return unless after_subset_queue_store
|
47
|
+
after_subset_queue_store.each do |block|
|
48
|
+
block.call(
|
49
|
+
KnapsackPro::Config::Env.queue_id,
|
50
|
+
KnapsackPro::Config::Env.subset_queue_id
|
51
|
+
)
|
52
|
+
end
|
46
53
|
end
|
47
54
|
|
48
55
|
def call_after_queue
|
49
|
-
return unless
|
50
|
-
|
51
|
-
|
52
|
-
|
56
|
+
return unless after_queue_store
|
57
|
+
after_queue_store.each do |block|
|
58
|
+
block.call(
|
59
|
+
KnapsackPro::Config::Env.queue_id
|
60
|
+
)
|
61
|
+
end
|
53
62
|
end
|
54
63
|
end
|
55
64
|
end
|
@@ -15,7 +15,7 @@ module KnapsackPro
|
|
15
15
|
Rake::Task[task_name].clear
|
16
16
|
end
|
17
17
|
|
18
|
-
Cucumber::Rake::Task.new(task_name) do |t|
|
18
|
+
::Cucumber::Rake::Task.new(task_name) do |t|
|
19
19
|
t.cucumber_opts = "#{args} --require #{runner.test_dir} -- #{runner.stringify_test_file_paths}"
|
20
20
|
end
|
21
21
|
Rake::Task[task_name].invoke
|
@@ -16,7 +16,7 @@ module KnapsackPro
|
|
16
16
|
cli_args = (args || '').split
|
17
17
|
# if user didn't provide the format then use explicitly default progress formatter
|
18
18
|
# in order to avoid KnapsackPro::Formatters::RSpecQueueSummaryFormatter being the only default formatter
|
19
|
-
if !cli_args.
|
19
|
+
if !cli_args.any? { |arg| arg.start_with?('-f') || arg.start_with?('--format')}
|
20
20
|
cli_args += ['--format', 'progress']
|
21
21
|
end
|
22
22
|
cli_args += [
|
@@ -79,8 +79,8 @@ module KnapsackPro
|
|
79
79
|
|
80
80
|
log_rspec_command(args, test_file_paths, :subset_queue)
|
81
81
|
|
82
|
-
options = RSpec::Core::ConfigurationOptions.new(cli_args)
|
83
|
-
exit_code = RSpec::Core::Runner.new(options).run($stderr, $stdout)
|
82
|
+
options = ::RSpec::Core::ConfigurationOptions.new(cli_args)
|
83
|
+
exit_code = ::RSpec::Core::Runner.new(options).run($stderr, $stdout)
|
84
84
|
exitstatus = exit_code if exit_code != 0
|
85
85
|
|
86
86
|
rspec_clear_examples
|
@@ -124,26 +124,26 @@ module KnapsackPro
|
|
124
124
|
#
|
125
125
|
# Keep formatters and report to accumulate info about failed/pending tests
|
126
126
|
def self.rspec_clear_examples
|
127
|
-
if RSpec::ExampleGroups.respond_to?(:remove_all_constants)
|
128
|
-
RSpec::ExampleGroups.remove_all_constants
|
127
|
+
if ::RSpec::ExampleGroups.respond_to?(:remove_all_constants)
|
128
|
+
::RSpec::ExampleGroups.remove_all_constants
|
129
129
|
else
|
130
|
-
RSpec::ExampleGroups.constants.each do |constant|
|
131
|
-
RSpec::ExampleGroups.__send__(:remove_const, constant)
|
130
|
+
::RSpec::ExampleGroups.constants.each do |constant|
|
131
|
+
::RSpec::ExampleGroups.__send__(:remove_const, constant)
|
132
132
|
end
|
133
133
|
end
|
134
|
-
RSpec.world.example_groups.clear
|
135
|
-
RSpec.configuration.start_time = ::RSpec::Core::Time.now
|
134
|
+
::RSpec.world.example_groups.clear
|
135
|
+
::RSpec.configuration.start_time = ::RSpec::Core::Time.now
|
136
136
|
|
137
137
|
if KnapsackPro::Config::Env.rspec_split_by_test_examples?
|
138
138
|
# Reset example group counts to ensure scoped example ids in metadata
|
139
139
|
# have correct index (not increased by each subsequent run).
|
140
140
|
# Solves this problem: https://github.com/rspec/rspec-core/issues/2721
|
141
|
-
RSpec.world.instance_variable_set(:@example_group_counts_by_spec_file, Hash.new(0))
|
141
|
+
::RSpec.world.instance_variable_set(:@example_group_counts_by_spec_file, Hash.new(0))
|
142
142
|
end
|
143
143
|
|
144
144
|
# skip reset filters for old RSpec versions
|
145
|
-
if RSpec.configuration.respond_to?(:reset_filters)
|
146
|
-
RSpec.configuration.reset_filters
|
145
|
+
if ::RSpec.configuration.respond_to?(:reset_filters)
|
146
|
+
::RSpec.configuration.reset_filters
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
@@ -15,7 +15,7 @@ module KnapsackPro
|
|
15
15
|
Rake::Task[task_name].clear
|
16
16
|
end
|
17
17
|
|
18
|
-
RSpec::Core::RakeTask.new(task_name) do |t|
|
18
|
+
::RSpec::Core::RakeTask.new(task_name) do |t|
|
19
19
|
# we cannot pass runner.test_file_paths array to t.pattern
|
20
20
|
# because pattern does not accept test example path like spec/a_spec.rb[1:2]
|
21
21
|
# instead we pass test files and test example paths to t.rspec_opts
|
@@ -7,7 +7,7 @@ module KnapsackPro
|
|
7
7
|
require 'rspec/core'
|
8
8
|
|
9
9
|
cli_format =
|
10
|
-
if Gem::Version.new(RSpec::Core::Version::STRING) < Gem::Version.new('3.6.0')
|
10
|
+
if Gem::Version.new(::RSpec::Core::Version::STRING) < Gem::Version.new('3.6.0')
|
11
11
|
require_relative '../formatters/rspec_json_formatter'
|
12
12
|
['--format', KnapsackPro::Formatters::RSpecJsonFormatter.to_s]
|
13
13
|
else
|
@@ -30,8 +30,8 @@ module KnapsackPro
|
|
30
30
|
'--out', report_path,
|
31
31
|
'--default-path', test_dir,
|
32
32
|
] + KnapsackPro::TestFilePresenter.paths(test_file_entities)
|
33
|
-
options = RSpec::Core::ConfigurationOptions.new(cli_args)
|
34
|
-
exit_code = RSpec::Core::Runner.new(options).run($stderr, $stdout)
|
33
|
+
options = ::RSpec::Core::ConfigurationOptions.new(cli_args)
|
34
|
+
exit_code = ::RSpec::Core::Runner.new(options).run($stderr, $stdout)
|
35
35
|
if exit_code != 0
|
36
36
|
raise 'There was problem to generate test examples for test suite'
|
37
37
|
end
|
data/lib/knapsack_pro/version.rb
CHANGED
@@ -22,7 +22,14 @@ describe KnapsackPro::Config::CI::GithubActions do
|
|
22
22
|
describe '#node_build_id' do
|
23
23
|
subject { described_class.new.node_build_id }
|
24
24
|
|
25
|
-
|
25
|
+
context 'when environment exists' do
|
26
|
+
let(:env) { { 'GITHUB_RUN_ID' => 2706 } }
|
27
|
+
it { should eql 2706 }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when environment doesn't exist" do
|
31
|
+
it { should be nil }
|
32
|
+
end
|
26
33
|
end
|
27
34
|
|
28
35
|
describe '#commit_hash' do
|
@@ -658,6 +658,20 @@ describe KnapsackPro::Config::Env do
|
|
658
658
|
end
|
659
659
|
end
|
660
660
|
|
661
|
+
describe '.rspec_test_example_detector_prefix' do
|
662
|
+
subject { described_class.rspec_test_example_detector_prefix }
|
663
|
+
|
664
|
+
context 'when ENV exists' do
|
665
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_RSPEC_TEST_EXAMPLE_DETECTOR_PREFIX' => '' }) }
|
666
|
+
it { should eq '' }
|
667
|
+
end
|
668
|
+
|
669
|
+
context "when ENV doesn't exist" do
|
670
|
+
before { stub_const("ENV", {}) }
|
671
|
+
it { should eq 'bundle exec' }
|
672
|
+
end
|
673
|
+
end
|
674
|
+
|
661
675
|
describe '.test_suite_token' do
|
662
676
|
subject { described_class.test_suite_token }
|
663
677
|
|
@@ -10,18 +10,30 @@ describe KnapsackPro::Hooks::Queue do
|
|
10
10
|
it { should be_nil }
|
11
11
|
end
|
12
12
|
|
13
|
-
context 'when callback is set' do
|
13
|
+
context 'when callback is set multiple times' do
|
14
14
|
let(:queue_id) { double }
|
15
15
|
|
16
16
|
before do
|
17
|
-
expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
|
17
|
+
expect(KnapsackPro::Config::Env).to receive(:queue_id).twice.and_return(queue_id)
|
18
18
|
|
19
|
+
$expected_called_blocks = []
|
20
|
+
|
21
|
+
described_class.before_queue do |q_id|
|
22
|
+
$expected_called_blocks << [:block_1_called, q_id]
|
23
|
+
end
|
19
24
|
described_class.before_queue do |q_id|
|
20
|
-
[:
|
25
|
+
$expected_called_blocks << [:block_2_called, q_id]
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
24
|
-
it
|
29
|
+
it 'each block is called' do
|
30
|
+
subject
|
31
|
+
|
32
|
+
expect($expected_called_blocks).to eq([
|
33
|
+
[:block_1_called, queue_id],
|
34
|
+
[:block_2_called, queue_id],
|
35
|
+
])
|
36
|
+
end
|
25
37
|
end
|
26
38
|
end
|
27
39
|
|
@@ -36,20 +48,32 @@ describe KnapsackPro::Hooks::Queue do
|
|
36
48
|
it { should be_nil }
|
37
49
|
end
|
38
50
|
|
39
|
-
context 'when callback is set' do
|
51
|
+
context 'when callback is set multiple times' do
|
40
52
|
let(:queue_id) { double }
|
41
53
|
let(:subset_queue_id) { double }
|
42
54
|
|
43
55
|
before do
|
44
|
-
expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
|
45
|
-
expect(KnapsackPro::Config::Env).to receive(:subset_queue_id).and_return(subset_queue_id)
|
56
|
+
expect(KnapsackPro::Config::Env).to receive(:queue_id).twice.and_return(queue_id)
|
57
|
+
expect(KnapsackPro::Config::Env).to receive(:subset_queue_id).twice.and_return(subset_queue_id)
|
58
|
+
|
59
|
+
$expected_called_blocks = []
|
46
60
|
|
47
61
|
described_class.after_subset_queue do |q_id, subset_q_id|
|
48
|
-
[:
|
62
|
+
$expected_called_blocks << [:block_1_called, q_id, subset_q_id]
|
63
|
+
end
|
64
|
+
described_class.after_subset_queue do |q_id, subset_q_id|
|
65
|
+
$expected_called_blocks << [:block_2_called, q_id, subset_q_id]
|
49
66
|
end
|
50
67
|
end
|
51
68
|
|
52
|
-
it
|
69
|
+
it 'each block is called' do
|
70
|
+
subject
|
71
|
+
|
72
|
+
expect($expected_called_blocks).to eq([
|
73
|
+
[:block_1_called, queue_id, subset_queue_id],
|
74
|
+
[:block_2_called, queue_id, subset_queue_id],
|
75
|
+
])
|
76
|
+
end
|
53
77
|
end
|
54
78
|
end
|
55
79
|
|
@@ -64,18 +88,30 @@ describe KnapsackPro::Hooks::Queue do
|
|
64
88
|
it { should be_nil }
|
65
89
|
end
|
66
90
|
|
67
|
-
context 'when callback is set' do
|
91
|
+
context 'when callback is set multiple times' do
|
68
92
|
let(:queue_id) { double }
|
69
93
|
|
70
94
|
before do
|
71
|
-
expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
|
95
|
+
expect(KnapsackPro::Config::Env).to receive(:queue_id).twice.and_return(queue_id)
|
96
|
+
|
97
|
+
$expected_called_blocks = []
|
72
98
|
|
73
99
|
described_class.after_queue do |q_id|
|
74
|
-
[:
|
100
|
+
$expected_called_blocks << [:block_1_called, q_id]
|
101
|
+
end
|
102
|
+
described_class.after_queue do |q_id|
|
103
|
+
$expected_called_blocks << [:block_2_called, q_id]
|
75
104
|
end
|
76
105
|
end
|
77
106
|
|
78
|
-
it
|
107
|
+
it 'each block is called' do
|
108
|
+
subject
|
109
|
+
|
110
|
+
expect($expected_called_blocks).to eq([
|
111
|
+
[:block_1_called, queue_id],
|
112
|
+
[:block_2_called, queue_id],
|
113
|
+
])
|
114
|
+
end
|
79
115
|
end
|
80
116
|
end
|
81
117
|
end
|
@@ -104,6 +104,31 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
104
104
|
subject
|
105
105
|
end
|
106
106
|
end
|
107
|
+
|
108
|
+
context 'when format param is provided without a delimiter' do
|
109
|
+
let(:args) { '-fMyCustomFormatter' }
|
110
|
+
|
111
|
+
it 'uses provided format param instead of default formatter progress' do
|
112
|
+
expected_exitstatus = 0
|
113
|
+
expected_accumulator = {
|
114
|
+
status: :completed,
|
115
|
+
exitstatus: expected_exitstatus
|
116
|
+
}
|
117
|
+
accumulator = {
|
118
|
+
status: :next,
|
119
|
+
runner: runner,
|
120
|
+
can_initialize_queue: true,
|
121
|
+
args: ['-fMyCustomFormatter', '--format', 'KnapsackPro::Formatters::RSpecQueueSummaryFormatter', '--default-path', 'fake-test-dir'],
|
122
|
+
exitstatus: 0,
|
123
|
+
all_test_file_paths: [],
|
124
|
+
}
|
125
|
+
expect(described_class).to receive(:run_tests).with(accumulator).and_return(expected_accumulator)
|
126
|
+
|
127
|
+
expect(Kernel).to receive(:exit).with(expected_exitstatus)
|
128
|
+
|
129
|
+
subject
|
130
|
+
end
|
131
|
+
end
|
107
132
|
end
|
108
133
|
|
109
134
|
context 'when args not provided' do
|
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:
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ArturT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|