knapsack_pro 9.0.0 → 9.1.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 +4 -4
- data/lib/knapsack_pro/adapters/minitest_adapter.rb +8 -13
- data/lib/knapsack_pro/client/connection.rb +1 -1
- data/lib/knapsack_pro/config/env.rb +1 -24
- data/lib/knapsack_pro/version.rb +1 -1
- metadata +2 -196
- data/.circleci/config.yml +0 -468
- data/.github/assets/install-button.png +0 -0
- data/.github/assets/knapsack-diamonds.png +0 -0
- data/.github/dependabot.yml +0 -11
- data/.github/pull_request_template.md +0 -11
- data/.gitignore +0 -39
- data/.rspec +0 -5
- data/CHANGELOG.md +0 -1995
- data/Gemfile +0 -13
- data/LICENSE +0 -22
- data/README.md +0 -90
- data/Rakefile +0 -2
- data/knapsack_pro.gemspec +0 -43
- data/spec/fixtures/test_file_list_source_file.txt +0 -6
- data/spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/invalid_test_suite_token.yml +0 -59
- data/spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/success.yml +0 -61
- data/spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/invalid_test_suite_token.yml +0 -50
- data/spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/success.yml +0 -50
- data/spec/integration/api/build_distributions_subset_spec.rb +0 -77
- data/spec/integration/api/build_subsets_create_spec.rb +0 -77
- data/spec/integration/runners/fallback_spec.rb +0 -131
- data/spec/integration/runners/queue/cucumber_runner_fallback_spec.rb +0 -129
- data/spec/integration/runners/queue/minitest_runner_fallback_spec.rb +0 -129
- data/spec/integration/runners/queue/rspec_runner.rb +0 -80
- data/spec/integration/runners/queue/rspec_runner_fallback_spec.rb +0 -137
- data/spec/integration/runners/queue/rspec_runner_spec.rb +0 -2672
- data/spec/knapsack_pro/adapters/base_adapter_spec.rb +0 -221
- data/spec/knapsack_pro/adapters/cucumber_adapter_spec.rb +0 -216
- data/spec/knapsack_pro/adapters/minitest_adapter_spec.rb +0 -189
- data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +0 -427
- data/spec/knapsack_pro/adapters/spinach_adapter_spec.rb +0 -61
- data/spec/knapsack_pro/adapters/test_unit_adapter_spec.rb +0 -86
- data/spec/knapsack_pro/base_allocator_builder_spec.rb +0 -102
- data/spec/knapsack_pro/build_distribution_fetcher_spec.rb +0 -89
- data/spec/knapsack_pro/client/api/action_spec.rb +0 -17
- data/spec/knapsack_pro/client/api/v1/base_spec.rb +0 -2
- data/spec/knapsack_pro/client/api/v1/build_distributions_spec.rb +0 -95
- data/spec/knapsack_pro/client/api/v1/build_subsets_spec.rb +0 -35
- data/spec/knapsack_pro/client/api/v1/queues_spec.rb +0 -83
- data/spec/knapsack_pro/client/connection_spec.rb +0 -581
- data/spec/knapsack_pro/config/ci/app_veyor_spec.rb +0 -87
- data/spec/knapsack_pro/config/ci/base_spec.rb +0 -10
- data/spec/knapsack_pro/config/ci/buildkite_spec.rb +0 -135
- data/spec/knapsack_pro/config/ci/circle_spec.rb +0 -122
- data/spec/knapsack_pro/config/ci/cirrus_ci_spec.rb +0 -87
- data/spec/knapsack_pro/config/ci/codefresh_spec.rb +0 -81
- data/spec/knapsack_pro/config/ci/codeship_spec.rb +0 -80
- data/spec/knapsack_pro/config/ci/github_actions_spec.rb +0 -140
- data/spec/knapsack_pro/config/ci/gitlab_ci_spec.rb +0 -137
- data/spec/knapsack_pro/config/ci/heroku_spec.rb +0 -87
- data/spec/knapsack_pro/config/ci/semaphore2_spec.rb +0 -133
- data/spec/knapsack_pro/config/ci/semaphore_spec.rb +0 -87
- data/spec/knapsack_pro/config/ci/travis_spec.rb +0 -73
- data/spec/knapsack_pro/config/env_generator_spec.rb +0 -52
- data/spec/knapsack_pro/config/env_spec.rb +0 -1291
- data/spec/knapsack_pro/config/temp_files_spec.rb +0 -25
- data/spec/knapsack_pro/crypto/branch_encryptor_spec.rb +0 -53
- data/spec/knapsack_pro/crypto/decryptor_spec.rb +0 -83
- data/spec/knapsack_pro/crypto/digestor_spec.rb +0 -13
- data/spec/knapsack_pro/crypto/encryptor_spec.rb +0 -58
- data/spec/knapsack_pro/formatters/time_tracker_fetcher_spec.rb +0 -27
- data/spec/knapsack_pro/formatters/time_tracker_spec.rb +0 -448
- data/spec/knapsack_pro/hooks/queue_spec.rb +0 -199
- data/spec/knapsack_pro/presenter_spec.rb +0 -57
- data/spec/knapsack_pro/pure/queue/rspec_pure_spec.rb +0 -248
- data/spec/knapsack_pro/queue_spec.rb +0 -35
- data/spec/knapsack_pro/report_spec.rb +0 -232
- data/spec/knapsack_pro/repository_adapter_initiator_spec.rb +0 -21
- data/spec/knapsack_pro/repository_adapters/base_adapter_spec.rb +0 -13
- data/spec/knapsack_pro/repository_adapters/env_adapter_spec.rb +0 -27
- data/spec/knapsack_pro/repository_adapters/git_adapter_spec.rb +0 -106
- data/spec/knapsack_pro/runners/base_runner_spec.rb +0 -87
- data/spec/knapsack_pro/runners/cucumber_runner_spec.rb +0 -92
- data/spec/knapsack_pro/runners/minitest_runner_spec.rb +0 -57
- data/spec/knapsack_pro/runners/queue/base_runner_spec.rb +0 -73
- data/spec/knapsack_pro/runners/queue/cucumber_runner_spec.rb +0 -209
- data/spec/knapsack_pro/runners/queue/minitest_runner_spec.rb +0 -203
- data/spec/knapsack_pro/runners/rspec_runner_spec.rb +0 -111
- data/spec/knapsack_pro/runners/spinach_runner_spec.rb +0 -56
- data/spec/knapsack_pro/runners/test_unit_runner_spec.rb +0 -62
- data/spec/knapsack_pro/slow_test_file_determiner_spec.rb +0 -119
- data/spec/knapsack_pro/slow_test_file_finder_spec.rb +0 -42
- data/spec/knapsack_pro/task_loader_spec.rb +0 -14
- data/spec/knapsack_pro/test_case_detectors/rspec_test_example_detector_spec.rb +0 -217
- data/spec/knapsack_pro/test_case_mergers/base_merger_spec.rb +0 -27
- data/spec/knapsack_pro/test_case_mergers/rspec_merger_spec.rb +0 -81
- data/spec/knapsack_pro/test_file_cleaner_spec.rb +0 -11
- data/spec/knapsack_pro/test_file_finder_spec.rb +0 -176
- data/spec/knapsack_pro/test_file_pattern_spec.rb +0 -49
- data/spec/knapsack_pro/test_file_presenter_spec.rb +0 -22
- data/spec/knapsack_pro/test_files_with_test_cases_composer_spec.rb +0 -41
- data/spec/knapsack_pro/test_flat_distributor_spec.rb +0 -60
- data/spec/knapsack_pro/tracker_spec.rb +0 -184
- data/spec/knapsack_pro/utils_spec.rb +0 -55
- data/spec/knapsack_pro_spec.rb +0 -116
- data/spec/spec_helper.rb +0 -47
- data/spec/support/.gitkeep +0 -0
- data/spec/support/fakes/cucumber.rb +0 -25
- data/spec/support/fakes/minitest.rb +0 -18
- data/spec/support/shared_examples/adapter.rb +0 -17
- data/spec_fake/controllers/users_controller_spec.rb +0 -0
- data/spec_fake/models/admin_spec.rb +0 -0
- data/spec_fake/models/user_spec.rb +0 -0
- data/spec_fake/spec_helper.rb +0 -0
- data/spec_time_tracker/spec_helper.rb +0 -29
- data/test_fake/a_test.rb +0 -0
- data/test_fake/b_test.rb +0 -0
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
require_relative '../../../lib/knapsack_pro/formatters/time_tracker'
|
|
2
|
-
|
|
3
|
-
describe KnapsackPro::Adapters::RSpecAdapter do
|
|
4
|
-
it 'backwards compatibility with knapsack gem old rspec adapter name' do
|
|
5
|
-
expect(KnapsackPro::Adapters::RspecAdapter.new).to be_kind_of(described_class)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it do
|
|
9
|
-
expect(described_class::TEST_DIR_PATTERN).to eq 'spec/**{,/*/**}/*_spec.rb'
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context do
|
|
13
|
-
before { expect(::RSpec).to receive(:configure).at_least(:once) }
|
|
14
|
-
it_behaves_like 'adapter'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe '.split_by_test_cases_enabled?' do
|
|
18
|
-
subject { described_class.split_by_test_cases_enabled? }
|
|
19
|
-
|
|
20
|
-
before do
|
|
21
|
-
expect(KnapsackPro::Config::Env).to receive(:rspec_split_by_test_examples?).and_return(rspec_split_by_test_examples_enabled)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
context 'when the RSpec split by test examples is enabled' do
|
|
25
|
-
let(:rspec_split_by_test_examples_enabled) { true }
|
|
26
|
-
|
|
27
|
-
it { expect(subject).to be true }
|
|
28
|
-
|
|
29
|
-
context 'when the RSpec version is < 3.3.0' do
|
|
30
|
-
before do
|
|
31
|
-
stub_const('RSpec::Core::Version::STRING', '3.2.0')
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it do
|
|
35
|
-
expect { subject }.to raise_error RuntimeError, 'RSpec >= 3.3.0 is required to split test files by test examples. Learn more: https://knapsackpro.com/perma/ruby/split-by-test-examples'
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
context 'when the RSpec split by test examples is disabled' do
|
|
41
|
-
let(:rspec_split_by_test_examples_enabled) { false }
|
|
42
|
-
|
|
43
|
-
it { expect(subject).to be false }
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe '.test_file_cases_for' do
|
|
48
|
-
let(:slow_test_files) do
|
|
49
|
-
[
|
|
50
|
-
'1_spec.rb',
|
|
51
|
-
'2_spec.rb',
|
|
52
|
-
'3_spec.rb',
|
|
53
|
-
'4_spec.rb',
|
|
54
|
-
'5_spec.rb',
|
|
55
|
-
]
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
subject { described_class.test_file_cases_for(slow_test_files) }
|
|
59
|
-
|
|
60
|
-
before do
|
|
61
|
-
logger = instance_double(Logger)
|
|
62
|
-
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
|
63
|
-
expect(logger).to receive(:info).with("Generating RSpec test examples JSON report for slow test files to prepare it to be split by test examples (by individual test cases). Thanks to that, a single slow test file can be split across parallel CI nodes. Analyzing 5 slow test files.")
|
|
64
|
-
|
|
65
|
-
cmd = 'RACK_ENV=test RAILS_ENV=test bundle exec rake knapsack_pro:rspec_test_example_detector'
|
|
66
|
-
expect(Kernel).to receive(:system).with(cmd).and_return(cmd_result)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
context 'when the rake task to detect RSpec test examples succeeded' do
|
|
70
|
-
let(:cmd_result) { true }
|
|
71
|
-
|
|
72
|
-
it 'returns test example paths for slow test files' do
|
|
73
|
-
rspec_test_example_detector = instance_double(KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector)
|
|
74
|
-
expect(KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector).to receive(:new).and_return(rspec_test_example_detector)
|
|
75
|
-
|
|
76
|
-
test_file_example_paths = double
|
|
77
|
-
expect(rspec_test_example_detector).to receive(:test_file_example_paths).and_return(test_file_example_paths)
|
|
78
|
-
|
|
79
|
-
expect(subject).to eq test_file_example_paths
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
context 'when the rake task to detect RSpec test examples failed' do
|
|
84
|
-
let(:cmd_result) { false }
|
|
85
|
-
|
|
86
|
-
it do
|
|
87
|
-
expect { subject }.to raise_error(RuntimeError, 'Could not generate JSON report for RSpec. Rake task failed when running RACK_ENV=test RAILS_ENV=test bundle exec rake knapsack_pro:rspec_test_example_detector')
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
describe '.has_format_option?' do
|
|
93
|
-
subject { described_class.has_format_option?(cli_args) }
|
|
94
|
-
|
|
95
|
-
context 'when format option is provided as -f' do
|
|
96
|
-
let(:cli_args) { ['-f', 'documentation'] }
|
|
97
|
-
|
|
98
|
-
it { expect(subject).to be true }
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
context 'when format option is provided as --format' do
|
|
102
|
-
let(:cli_args) { ['--format', 'documentation'] }
|
|
103
|
-
|
|
104
|
-
it { expect(subject).to be true }
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
context 'when format option is provided without delimiter' do
|
|
108
|
-
let(:cli_args) { ['-fd'] }
|
|
109
|
-
|
|
110
|
-
it { expect(subject).to be true }
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
context 'when format option is not provided' do
|
|
114
|
-
let(:cli_args) { ['--fake', 'value'] }
|
|
115
|
-
|
|
116
|
-
it { expect(subject).to be false }
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
describe '.has_require_rails_helper_option?' do
|
|
121
|
-
subject { described_class.has_require_rails_helper_option?(cli_args) }
|
|
122
|
-
|
|
123
|
-
context 'when require option is provided as -r' do
|
|
124
|
-
let(:cli_args) { ['-r', 'rails_helper'] }
|
|
125
|
-
|
|
126
|
-
it { expect(subject).to be true }
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
context 'when require option is provided as --require' do
|
|
130
|
-
let(:cli_args) { ['--require', 'rails_helper'] }
|
|
131
|
-
|
|
132
|
-
it { expect(subject).to be true }
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
context 'when require option is provided without delimiter' do
|
|
136
|
-
let(:cli_args) { ['-rrails_helper'] }
|
|
137
|
-
|
|
138
|
-
it { expect(subject).to be true }
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
context 'when require option is not provided' do
|
|
142
|
-
let(:cli_args) { ['--fake', 'value'] }
|
|
143
|
-
|
|
144
|
-
it { expect(subject).to be false }
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
describe '.id_path?' do
|
|
149
|
-
subject { described_class.id_path?(path) }
|
|
150
|
-
|
|
151
|
-
context 'when the path is an RSpec path with id' do
|
|
152
|
-
let(:path) { 'spec/features/a_spec.rb[1:1:7:1]' }
|
|
153
|
-
|
|
154
|
-
it { is_expected.to be true }
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
context 'when the path is an RSpec path with multiple ids' do
|
|
158
|
-
let(:path) { 'spec/features/a_spec.rb[1:1:7:1, 1:2]' }
|
|
159
|
-
|
|
160
|
-
it { is_expected.to be true }
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
context 'when the path is an RSpec path with no id' do
|
|
164
|
-
let(:path) { 'spec/features/a_spec.rb' }
|
|
165
|
-
|
|
166
|
-
it { is_expected.to be false }
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
context 'when the path is a Turnip path with id' do
|
|
170
|
-
let(:path) { 'spec/acceptance/a.feature[1:1:7:1]' }
|
|
171
|
-
|
|
172
|
-
it { is_expected.to be true }
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
context 'when the path is a Turnip path with multiple ids' do
|
|
176
|
-
let(:path) { 'spec/acceptance/a.feature[1:1:7:1,1:2]' }
|
|
177
|
-
|
|
178
|
-
it { is_expected.to be true }
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
context 'when the path is a Turnip path with no id' do
|
|
182
|
-
let(:path) { 'spec/acceptance/a.feature' }
|
|
183
|
-
|
|
184
|
-
it { is_expected.to be false }
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
describe '.rails_helper_exists?' do
|
|
189
|
-
subject { described_class.rails_helper_exists?(test_dir) }
|
|
190
|
-
|
|
191
|
-
let(:test_dir) { 'spec_fake' }
|
|
192
|
-
|
|
193
|
-
context 'when rails_helper exists' do
|
|
194
|
-
before do
|
|
195
|
-
File.open("#{test_dir}/rails_helper.rb", 'w')
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
after do
|
|
199
|
-
FileUtils.rm("#{test_dir}/rails_helper.rb")
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
it { expect(subject).to be true }
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
context 'when rails_helper does not exist' do
|
|
206
|
-
before do
|
|
207
|
-
FileUtils.rm_f("#{test_dir}/rails_helper.rb")
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
it { expect(subject).to be false }
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
describe '.order_option' do
|
|
215
|
-
subject { described_class.order_option(cli_args) }
|
|
216
|
-
|
|
217
|
-
context "when order is 'defined'" do
|
|
218
|
-
let(:cli_args) { ['--order', 'defined'] }
|
|
219
|
-
|
|
220
|
-
it { expect(subject).to eq 'defined' }
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
context "when order is 'recently-modified'" do
|
|
224
|
-
let(:cli_args) { ['--order', 'recently-modified'] }
|
|
225
|
-
|
|
226
|
-
it { expect(subject).to eq 'recently-modified' }
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
context "when order is 'rand'" do
|
|
230
|
-
let(:cli_args) { ['--order', 'rand'] }
|
|
231
|
-
|
|
232
|
-
it { expect(subject).to eq 'rand' }
|
|
233
|
-
|
|
234
|
-
context 'with the seed' do
|
|
235
|
-
let(:cli_args) { ['--order', 'rand:123456'] }
|
|
236
|
-
|
|
237
|
-
it { expect(subject).to eq 'rand:123456' }
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
context "when order is 'random'" do
|
|
242
|
-
let(:cli_args) { ['--order', 'random'] }
|
|
243
|
-
|
|
244
|
-
it { expect(subject).to eq 'random' }
|
|
245
|
-
|
|
246
|
-
context 'with the seed' do
|
|
247
|
-
let(:cli_args) { ['--order', 'random:123456'] }
|
|
248
|
-
|
|
249
|
-
it { expect(subject).to eq 'random:123456' }
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
context 'when some custom order is specified' do
|
|
254
|
-
let(:cli_args) { ['--order', 'some-custom-order'] }
|
|
255
|
-
|
|
256
|
-
it { expect(subject).to eq 'some-custom-order' }
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
context "when the seed is given with the --seed command" do
|
|
260
|
-
let(:cli_args) { ['--seed', '123456'] }
|
|
261
|
-
|
|
262
|
-
it { expect(subject).to eq 'rand:123456' }
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
describe '.remove_formatters' do
|
|
267
|
-
subject { described_class.remove_formatters(cli_args) }
|
|
268
|
-
|
|
269
|
-
context "when CLI args include formatters" do
|
|
270
|
-
let(:cli_args) { ['-t', 'awesome_tag', '-f', 'documentation', '-o', '/tmp/documentation.txt', '--tag', 'mytag', '--format', 'json', '--out', '/tmp/file.json', '--no-color'] }
|
|
271
|
-
|
|
272
|
-
it 'removes formatters and the related output file options' do
|
|
273
|
-
expect(subject).to eq ['-t', 'awesome_tag', '--tag', 'mytag', '--no-color']
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
describe '.file_path_for' do
|
|
279
|
-
let(:current_example) { ::RSpec.describe.example }
|
|
280
|
-
|
|
281
|
-
subject { described_class.file_path_for(current_example) }
|
|
282
|
-
|
|
283
|
-
context "when id ends in _spec.rb" do
|
|
284
|
-
it "returns the first part of the id" do
|
|
285
|
-
allow(current_example).to receive(:id).and_return("./foo_spec.rb[1:1]")
|
|
286
|
-
|
|
287
|
-
expect(subject).to eq('./foo_spec.rb')
|
|
288
|
-
end
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
context "when id does not end in _spec.rb" do
|
|
292
|
-
it "returns the file_path" do
|
|
293
|
-
allow(current_example).to receive(:id).and_return("./foo.rb")
|
|
294
|
-
allow(current_example).to receive(:metadata).and_return(file_path: "./foo_spec.rb")
|
|
295
|
-
|
|
296
|
-
expect(subject).to eq('./foo_spec.rb')
|
|
297
|
-
end
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
context "when id and file_path do not end in _spec.rb" do
|
|
301
|
-
it "returns the example_group's file_path" do
|
|
302
|
-
allow(current_example).to receive(:id).and_return("./foo.rb")
|
|
303
|
-
allow(current_example).to receive(:metadata).and_return(
|
|
304
|
-
file_path: "./foo.rb", example_group: { file_path: "./foo_spec.rb" }
|
|
305
|
-
)
|
|
306
|
-
|
|
307
|
-
expect(subject).to eq('./foo_spec.rb')
|
|
308
|
-
end
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
context "when id, file_path, and example_group's file_path do not end in _spec.rb" do
|
|
312
|
-
it "returns the top_level_group's file_path" do
|
|
313
|
-
allow(current_example).to receive(:id).and_return("./foo.rb")
|
|
314
|
-
allow(current_example).to receive(:metadata).and_return(
|
|
315
|
-
file_path: "./foo.rb",
|
|
316
|
-
example_group: {
|
|
317
|
-
file_path: "./foo.rb",
|
|
318
|
-
parent_example_group: {
|
|
319
|
-
file_path: "./foo_spec.rb",
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
)
|
|
323
|
-
|
|
324
|
-
expect(subject).to eq('./foo_spec.rb')
|
|
325
|
-
end
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
context "when id, file_path, example_group's, and top_level_group's file_path do not end in _spec.rb" do
|
|
329
|
-
it "returns empty string" do
|
|
330
|
-
allow(current_example).to receive(:id).and_return("./foo.rb")
|
|
331
|
-
allow(current_example).to receive(:metadata).and_return(
|
|
332
|
-
file_path: "./foo.rb",
|
|
333
|
-
example_group: {
|
|
334
|
-
file_path: "./foo.rb",
|
|
335
|
-
parent_example_group: {
|
|
336
|
-
file_path: "./foo.rb",
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
)
|
|
340
|
-
|
|
341
|
-
expect(subject).to eq('')
|
|
342
|
-
end
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
context "when id does not end in .feature (nor _spec.rb)" do
|
|
346
|
-
it "returns the file_path" do
|
|
347
|
-
allow(current_example).to receive(:id).and_return("./foo.rb")
|
|
348
|
-
allow(current_example).to receive(:metadata).and_return(file_path: "./foo.feature")
|
|
349
|
-
|
|
350
|
-
expect(subject).to eq("./foo.feature")
|
|
351
|
-
end
|
|
352
|
-
end
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
describe 'private .scheduled_paths' do
|
|
356
|
-
subject { described_class.send(:scheduled_paths) }
|
|
357
|
-
|
|
358
|
-
context 'when the RSpec configuration has files or directories to run' do
|
|
359
|
-
it 'returns list of test files passed to RSpec (if this fails then the internal RSpec API changed and we must start supporting a new RSpec version as well)' do
|
|
360
|
-
expect(subject).not_to be_empty
|
|
361
|
-
end
|
|
362
|
-
end
|
|
363
|
-
|
|
364
|
-
context "when the RSpec configuration has no files or directories to run (when the internal RSpec API changed and we don't support the new RSpec version yet)" do
|
|
365
|
-
before do
|
|
366
|
-
expect(described_class).to receive(:rspec_configuration).and_return(double(:object_with_no_instance_variables))
|
|
367
|
-
end
|
|
368
|
-
|
|
369
|
-
it 'fallbacks to an empty array to not blow up Knapsack Pro' do
|
|
370
|
-
expect(subject).to eq([])
|
|
371
|
-
end
|
|
372
|
-
end
|
|
373
|
-
end
|
|
374
|
-
|
|
375
|
-
describe 'bind methods' do
|
|
376
|
-
let(:config) { double }
|
|
377
|
-
|
|
378
|
-
describe '#bind_time_tracker' do
|
|
379
|
-
let(:current_example) { double(metadata: {}) }
|
|
380
|
-
|
|
381
|
-
context "when the example's metadata has :focus tag AND RSpec inclusion rule includes :focus" do
|
|
382
|
-
let(:current_example) { double(metadata: { focus: true }) }
|
|
383
|
-
let(:test_path) { 'spec/a_spec.rb' }
|
|
384
|
-
|
|
385
|
-
it do
|
|
386
|
-
expect(config).to receive(:around).with(:each).and_yield(current_example)
|
|
387
|
-
expect(::RSpec).to receive(:configure).and_yield(config)
|
|
388
|
-
|
|
389
|
-
expect(described_class).to receive(:file_path_for).with(current_example).and_return(test_path)
|
|
390
|
-
|
|
391
|
-
expect(described_class).to receive_message_chain(:rspec_configuration, :filter, :rules, :[]).with(:focus).and_return(true)
|
|
392
|
-
|
|
393
|
-
expect {
|
|
394
|
-
subject.bind_time_tracker
|
|
395
|
-
}.to raise_error /Knapsack Pro found an example tagged with focus in spec\/a_spec\.rb/i
|
|
396
|
-
end
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
context 'with no focus' do
|
|
400
|
-
it 'records time for current test path' do
|
|
401
|
-
expect(config).to receive(:around).with(:each).and_yield(current_example)
|
|
402
|
-
expect(config).to receive(:append_after).with(:suite)
|
|
403
|
-
expect(::RSpec).to receive(:configure).at_least(1).and_yield(config)
|
|
404
|
-
|
|
405
|
-
expect(current_example).to receive(:run)
|
|
406
|
-
|
|
407
|
-
subject.bind_time_tracker
|
|
408
|
-
end
|
|
409
|
-
end
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
describe '#bind_save_report' do
|
|
413
|
-
it do
|
|
414
|
-
expect(config).to receive(:after).with(:suite).and_yield
|
|
415
|
-
expect(::RSpec).to receive(:configure).and_yield(config)
|
|
416
|
-
|
|
417
|
-
time_tracker = instance_double(KnapsackPro::Formatters::TimeTracker)
|
|
418
|
-
times = [{ path: "foo_spec.rb", time_execution: 1.0 }]
|
|
419
|
-
expect(time_tracker).to receive(:batch).and_return(times)
|
|
420
|
-
expect(KnapsackPro::Formatters::TimeTrackerFetcher).to receive(:call).and_return(time_tracker)
|
|
421
|
-
expect(KnapsackPro::Report).to receive(:save).with(times)
|
|
422
|
-
|
|
423
|
-
subject.bind_save_report
|
|
424
|
-
end
|
|
425
|
-
end
|
|
426
|
-
end
|
|
427
|
-
end
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::Adapters::SpinachAdapter do
|
|
2
|
-
it do
|
|
3
|
-
expect(described_class::TEST_DIR_PATTERN).to eq 'features/**{,/*/**}/*.feature'
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
context do
|
|
7
|
-
it_behaves_like 'adapter'
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
describe '.test_path' do
|
|
11
|
-
let(:scenario_data) do
|
|
12
|
-
double(feature: double(filename: 'a.feature'))
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
subject { described_class.test_path(scenario_data) }
|
|
16
|
-
|
|
17
|
-
it { should eql 'a.feature' }
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe 'bind methods' do
|
|
21
|
-
describe '#bind_time_tracker' do
|
|
22
|
-
let(:block) { double }
|
|
23
|
-
let(:tracker) { instance_double(KnapsackPro::Tracker) }
|
|
24
|
-
let(:logger) { instance_double(Logger) }
|
|
25
|
-
let(:global_time) { 'Global time: 01m 05s' }
|
|
26
|
-
let(:test_path) { 'features/a.feature' }
|
|
27
|
-
let(:scenario_data) do
|
|
28
|
-
double(feature: double(filename: test_path))
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it do
|
|
32
|
-
expect(Spinach.hooks).to receive(:before_scenario).and_yield(scenario_data, nil)
|
|
33
|
-
|
|
34
|
-
allow(KnapsackPro).to receive(:tracker).and_return(tracker)
|
|
35
|
-
expect(described_class).to receive(:test_path).with(scenario_data).and_return(test_path)
|
|
36
|
-
expect(tracker).to receive(:current_test_path=).with(test_path)
|
|
37
|
-
expect(tracker).to receive(:start_timer)
|
|
38
|
-
|
|
39
|
-
expect(Spinach.hooks).to receive(:after_scenario).and_yield
|
|
40
|
-
expect(tracker).to receive(:stop_timer)
|
|
41
|
-
|
|
42
|
-
expect(Spinach.hooks).to receive(:after_run).and_yield
|
|
43
|
-
expect(KnapsackPro::Presenter).to receive(:global_time).and_return(global_time)
|
|
44
|
-
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
|
45
|
-
expect(logger).to receive(:debug).with(global_time)
|
|
46
|
-
|
|
47
|
-
subject.bind_time_tracker
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe '#bind_save_report' do
|
|
52
|
-
it do
|
|
53
|
-
expect(Spinach.hooks).to receive(:after_run).and_yield
|
|
54
|
-
|
|
55
|
-
expect(KnapsackPro::Report).to receive(:save)
|
|
56
|
-
|
|
57
|
-
subject.bind_save_report
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# fake class to make tests pass and to avoid require 'test/unit/testcase' to not break RSpec
|
|
2
|
-
# https://www.rubydoc.info/gems/test-unit/3.4.1/Test/Unit/TestSuite
|
|
3
|
-
module Test
|
|
4
|
-
module Unit
|
|
5
|
-
class TestSuite
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
describe KnapsackPro::Adapters::TestUnitAdapter do
|
|
11
|
-
it do
|
|
12
|
-
expect(described_class::TEST_DIR_PATTERN).to eq 'test/**{,/*/**}/*_test.rb'
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe '.test_path' do
|
|
16
|
-
subject { described_class.test_path(obj) }
|
|
17
|
-
|
|
18
|
-
before do
|
|
19
|
-
parent_of_test_dir = File.expand_path('../../../', File.dirname(__FILE__))
|
|
20
|
-
described_class.class_variable_set(:@@parent_of_test_dir, parent_of_test_dir)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context 'when regular test' do
|
|
24
|
-
class FakeTestUnitTest
|
|
25
|
-
def method_name
|
|
26
|
-
"test_something"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_something
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
class FakeTestUnitTestSuite
|
|
34
|
-
def tests
|
|
35
|
-
[FakeTestUnitTest.new]
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
let(:obj) { FakeTestUnitTestSuite.new }
|
|
40
|
-
|
|
41
|
-
it { should eq './spec/knapsack_pro/adapters/test_unit_adapter_spec.rb' }
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
describe 'bind methods' do
|
|
46
|
-
describe '#bind_time_tracker' do
|
|
47
|
-
let(:logger) { instance_double(Logger) }
|
|
48
|
-
let(:global_time) { 'Global time: 01m 05s' }
|
|
49
|
-
|
|
50
|
-
it do
|
|
51
|
-
expect(Test::Unit::TestSuite).to receive(:send).with(:prepend, KnapsackPro::Adapters::TestUnitAdapter::BindTimeTrackerTestUnitPlugin)
|
|
52
|
-
|
|
53
|
-
expect(subject).to receive(:add_post_run_callback).and_yield
|
|
54
|
-
|
|
55
|
-
expect(KnapsackPro::Presenter).to receive(:global_time).and_return(global_time)
|
|
56
|
-
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
|
57
|
-
expect(logger).to receive(:debug).with(global_time)
|
|
58
|
-
|
|
59
|
-
subject.bind_time_tracker
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
describe '#bind_save_report' do
|
|
64
|
-
it do
|
|
65
|
-
expect(subject).to receive(:add_post_run_callback).and_yield
|
|
66
|
-
|
|
67
|
-
expect(KnapsackPro::Report).to receive(:save)
|
|
68
|
-
|
|
69
|
-
subject.bind_save_report
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe '#set_test_helper_path' do
|
|
75
|
-
let(:adapter) { described_class.new }
|
|
76
|
-
let(:test_helper_path) { '/code/project/test/test_helper.rb' }
|
|
77
|
-
|
|
78
|
-
subject { adapter.set_test_helper_path(test_helper_path) }
|
|
79
|
-
|
|
80
|
-
after do
|
|
81
|
-
expect(described_class.class_variable_get(:@@parent_of_test_dir)).to eq '/code/project'
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it { should eql '/code/project' }
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::BaseAllocatorBuilder do
|
|
2
|
-
let(:adapter_class) { KnapsackPro::Adapters::BaseAdapter }
|
|
3
|
-
let(:allocator_builder) { described_class.new(adapter_class) }
|
|
4
|
-
|
|
5
|
-
describe 'initialize method' do
|
|
6
|
-
context 'when unknown adapter (base adapter)' do
|
|
7
|
-
let(:adapter_class) { KnapsackPro::Adapters::BaseAdapter }
|
|
8
|
-
|
|
9
|
-
it do
|
|
10
|
-
allocator_builder
|
|
11
|
-
expect(ENV['KNAPSACK_PRO_TEST_RUNNER']).to be_nil
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'when RSpec adapter' do
|
|
16
|
-
let(:adapter_class) { KnapsackPro::Adapters::RSpecAdapter }
|
|
17
|
-
|
|
18
|
-
it do
|
|
19
|
-
allocator_builder
|
|
20
|
-
expect(ENV['KNAPSACK_PRO_TEST_RUNNER']).to eq 'rspec'
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
context 'when Cucumber adapter' do
|
|
25
|
-
let(:adapter_class) { KnapsackPro::Adapters::CucumberAdapter }
|
|
26
|
-
|
|
27
|
-
it do
|
|
28
|
-
allocator_builder
|
|
29
|
-
expect(ENV['KNAPSACK_PRO_TEST_RUNNER']).to eq 'cucumber'
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when Minitest adapter' do
|
|
34
|
-
let(:adapter_class) { KnapsackPro::Adapters::MinitestAdapter }
|
|
35
|
-
|
|
36
|
-
it do
|
|
37
|
-
allocator_builder
|
|
38
|
-
expect(ENV['KNAPSACK_PRO_TEST_RUNNER']).to eq 'minitest'
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
context 'when Spinach adapter' do
|
|
43
|
-
let(:adapter_class) { KnapsackPro::Adapters::SpinachAdapter }
|
|
44
|
-
|
|
45
|
-
it do
|
|
46
|
-
allocator_builder
|
|
47
|
-
expect(ENV['KNAPSACK_PRO_TEST_RUNNER']).to eq 'spinach'
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context 'when Test::Unit adapter' do
|
|
52
|
-
let(:adapter_class) { KnapsackPro::Adapters::TestUnitAdapter }
|
|
53
|
-
|
|
54
|
-
it do
|
|
55
|
-
allocator_builder
|
|
56
|
-
expect(ENV['KNAPSACK_PRO_TEST_RUNNER']).to eq 'test-unit'
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe '#allocator' do
|
|
62
|
-
subject { allocator_builder.allocator }
|
|
63
|
-
|
|
64
|
-
it do
|
|
65
|
-
expect { subject }.to raise_error(NotImplementedError)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
describe '#test_dir' do
|
|
70
|
-
subject { allocator_builder.test_dir }
|
|
71
|
-
|
|
72
|
-
before do
|
|
73
|
-
expect(KnapsackPro::Config::Env).to receive(:test_dir).and_return(test_dir)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
context 'when test_dir is defined in ENV' do
|
|
77
|
-
let(:test_dir) { double }
|
|
78
|
-
|
|
79
|
-
it { should eq test_dir }
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
context 'when test_dir is not defined in ENV' do
|
|
83
|
-
let(:test_dir) { nil }
|
|
84
|
-
|
|
85
|
-
before do
|
|
86
|
-
expect(KnapsackPro::TestFilePattern).to receive(:call).with(adapter_class).and_return(test_file_pattern)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
context 'when single pattern' do
|
|
90
|
-
let(:test_file_pattern) { 'spec/**{,/*/**}/*_spec.rb' }
|
|
91
|
-
|
|
92
|
-
it { should eq 'spec' }
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
context 'when multiple patterns' do
|
|
96
|
-
let(:test_file_pattern) { '{spec/controllers/**/*.rb,spec/decorators/**/*.rb}' }
|
|
97
|
-
|
|
98
|
-
it { should eq 'spec' }
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|