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,232 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::Report do
|
|
2
|
-
describe '.save' do
|
|
3
|
-
subject { described_class.save }
|
|
4
|
-
|
|
5
|
-
it do
|
|
6
|
-
test_files = [double]
|
|
7
|
-
tracker = instance_double(KnapsackPro::Tracker, to_a: test_files)
|
|
8
|
-
expect(KnapsackPro).to receive(:tracker).and_return(tracker)
|
|
9
|
-
expect(described_class).to receive(:create_build_subset).with(test_files)
|
|
10
|
-
|
|
11
|
-
subject
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe '.save_subset_queue_to_file' do
|
|
16
|
-
let(:fake_path) { SecureRandom.uuid }
|
|
17
|
-
|
|
18
|
-
subject { described_class.save_subset_queue_to_file }
|
|
19
|
-
|
|
20
|
-
before do
|
|
21
|
-
test_files = [{path: fake_path}]
|
|
22
|
-
tracker = instance_double(KnapsackPro::Tracker, to_a: test_files)
|
|
23
|
-
expect(KnapsackPro).to receive(:tracker).and_return(tracker)
|
|
24
|
-
|
|
25
|
-
subset_queue_id = 'fake-subset-queue-id'
|
|
26
|
-
expect(KnapsackPro::Config::Env).to receive(:subset_queue_id).and_return(subset_queue_id)
|
|
27
|
-
|
|
28
|
-
expect(KnapsackPro::Config::TempFiles).to receive(:ensure_temp_directory_exists!)
|
|
29
|
-
|
|
30
|
-
queue_id = 'fake-queue-id'
|
|
31
|
-
expect(KnapsackPro::Config::Env).to receive(:queue_id).twice.and_return(queue_id)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it do
|
|
35
|
-
subject
|
|
36
|
-
|
|
37
|
-
expect(
|
|
38
|
-
JSON.parse(
|
|
39
|
-
File.read('.knapsack_pro/queue/fake-queue-id/fake-subset-queue-id.json')
|
|
40
|
-
)
|
|
41
|
-
).to eq([
|
|
42
|
-
{ 'path' => fake_path }
|
|
43
|
-
])
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe '.save_node_queue_to_api' do
|
|
48
|
-
context 'when json files with recorded time does exist and test files have measured and default time execution' do
|
|
49
|
-
let(:json_test_file_a_path) { double }
|
|
50
|
-
let(:json_test_file_a) { [{ 'path' => 'a_spec.rb', 'time_execution' => 0.1234 }] }
|
|
51
|
-
|
|
52
|
-
let(:json_test_file_b_path) { double }
|
|
53
|
-
let(:json_test_file_b) { [{ 'path' => 'b_spec.rb', 'time_execution' => KnapsackPro::Tracker::DEFAULT_TEST_FILE_TIME }] }
|
|
54
|
-
|
|
55
|
-
subject { described_class.save_node_queue_to_api }
|
|
56
|
-
|
|
57
|
-
before do
|
|
58
|
-
queue_id = 'fake-queue-id'
|
|
59
|
-
expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
|
|
60
|
-
|
|
61
|
-
expect(Dir).to receive(:glob).with('.knapsack_pro/queue/fake-queue-id/*.json').and_return([
|
|
62
|
-
json_test_file_a_path,
|
|
63
|
-
json_test_file_b_path
|
|
64
|
-
])
|
|
65
|
-
|
|
66
|
-
expect(File).to receive(:read).with(json_test_file_a_path).and_return(json_test_file_a.to_json)
|
|
67
|
-
expect(File).to receive(:read).with(json_test_file_b_path).and_return(json_test_file_b.to_json)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it 'creates build subset for 2 recorded test files timing' do
|
|
71
|
-
expect(KnapsackPro).not_to receive(:logger)
|
|
72
|
-
|
|
73
|
-
expect(described_class).to receive(:create_build_subset).with(
|
|
74
|
-
json_test_file_a + json_test_file_b
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
subject
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
context 'when json files with recorded time does exist and all test files have default time execution' do
|
|
82
|
-
let(:json_test_file_a_path) { double }
|
|
83
|
-
let(:json_test_file_a) { [{ 'path' => 'a_spec.rb', 'time_execution' => KnapsackPro::Tracker::DEFAULT_TEST_FILE_TIME }] }
|
|
84
|
-
|
|
85
|
-
let(:json_test_file_b_path) { double }
|
|
86
|
-
let(:json_test_file_b) { [{ 'path' => 'b_spec.rb', 'time_execution' => KnapsackPro::Tracker::DEFAULT_TEST_FILE_TIME }] }
|
|
87
|
-
|
|
88
|
-
subject { described_class.save_node_queue_to_api }
|
|
89
|
-
|
|
90
|
-
before do
|
|
91
|
-
queue_id = 'fake-queue-id'
|
|
92
|
-
expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
|
|
93
|
-
|
|
94
|
-
expect(Dir).to receive(:glob).with('.knapsack_pro/queue/fake-queue-id/*.json').and_return([
|
|
95
|
-
json_test_file_a_path,
|
|
96
|
-
json_test_file_b_path
|
|
97
|
-
])
|
|
98
|
-
|
|
99
|
-
expect(File).to receive(:read).with(json_test_file_a_path).and_return(json_test_file_a.to_json)
|
|
100
|
-
expect(File).to receive(:read).with(json_test_file_b_path).and_return(json_test_file_b.to_json)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it 'logs error on lost info about recorded timing for test files due missing json files AND creates empty build subset' do
|
|
104
|
-
logger = instance_double(Logger)
|
|
105
|
-
expect(KnapsackPro).to receive(:logger).exactly(4).and_return(logger)
|
|
106
|
-
expect(logger).to receive(:warn).with('2 test files were executed on this CI node but the recorded time was lost due to:')
|
|
107
|
-
expect(logger).to receive(:warn).with('1. Please ensure you do not remove the contents of the .knapsack_pro directory between tests run.')
|
|
108
|
-
expect(logger).to receive(:warn).with("2. Ensure you've added Knapsack::Adapters::RSpecAdapter.bind in your rails_helper.rb or spec_helper.rb. Please follow the installation guide again: https://knapsackpro.com/perma/ruby/installation-guide")
|
|
109
|
-
expect(logger).to receive(:warn).with('3. Another potential reason for this warning is that all your tests are empty test files, pending tests, or they have syntax errors, and the time execution was not recorded for them.')
|
|
110
|
-
|
|
111
|
-
expect(described_class).to receive(:create_build_subset).with(
|
|
112
|
-
json_test_file_a + json_test_file_b
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
subject
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
context 'when json files with recorded time does not exist' do
|
|
120
|
-
subject { described_class.save_node_queue_to_api }
|
|
121
|
-
|
|
122
|
-
before do
|
|
123
|
-
queue_id = 'fake-queue-id'
|
|
124
|
-
expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
|
|
125
|
-
|
|
126
|
-
expect(Dir).to receive(:glob).with('.knapsack_pro/queue/fake-queue-id/*.json').and_return([])
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it 'logs warning about reasons why no test files were executed on this CI node' do
|
|
130
|
-
logger = instance_double(Logger)
|
|
131
|
-
expect(KnapsackPro).to receive(:logger).exactly(2).and_return(logger)
|
|
132
|
-
expect(logger).to receive(:warn).with('No test files were executed on this CI node.')
|
|
133
|
-
expect(logger).to receive(:debug).with('This CI node likely started work late after the test files were already executed by other CI nodes consuming the queue.')
|
|
134
|
-
|
|
135
|
-
expect(described_class).to receive(:create_build_subset).with([])
|
|
136
|
-
|
|
137
|
-
subject
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
describe '.create_build_subset' do
|
|
143
|
-
subject { described_class.create_build_subset(test_files) }
|
|
144
|
-
|
|
145
|
-
before do
|
|
146
|
-
commit_hash = double
|
|
147
|
-
branch = double
|
|
148
|
-
repository_adapter = instance_double(KnapsackPro::RepositoryAdapters::EnvAdapter, commit_hash: commit_hash, branch: branch)
|
|
149
|
-
expect(KnapsackPro::RepositoryAdapterInitiator).to receive(:call).and_return(repository_adapter)
|
|
150
|
-
|
|
151
|
-
unsymbolize_test_files = double
|
|
152
|
-
expect(KnapsackPro::Utils).to receive(:unsymbolize).with(test_files).and_return(unsymbolize_test_files)
|
|
153
|
-
|
|
154
|
-
encrypted_test_files = double
|
|
155
|
-
expect(KnapsackPro::Crypto::Encryptor).to receive(:call).with(unsymbolize_test_files).and_return(encrypted_test_files)
|
|
156
|
-
|
|
157
|
-
encrypted_branch = double
|
|
158
|
-
expect(KnapsackPro::Crypto::BranchEncryptor).to receive(:call).with(repository_adapter.branch).and_return(encrypted_branch)
|
|
159
|
-
|
|
160
|
-
node_total = double
|
|
161
|
-
node_index = double
|
|
162
|
-
expect(KnapsackPro::Config::Env).to receive(:ci_node_total).and_return(node_total)
|
|
163
|
-
expect(KnapsackPro::Config::Env).to receive(:ci_node_index).and_return(node_index)
|
|
164
|
-
|
|
165
|
-
action = double
|
|
166
|
-
expect(KnapsackPro::Client::API::V1::BuildSubsets).to receive(:create).with({
|
|
167
|
-
commit_hash: commit_hash,
|
|
168
|
-
branch: encrypted_branch,
|
|
169
|
-
node_total: node_total,
|
|
170
|
-
node_index: node_index,
|
|
171
|
-
test_files: encrypted_test_files,
|
|
172
|
-
}).and_return(action)
|
|
173
|
-
|
|
174
|
-
connection = instance_double(KnapsackPro::Client::Connection, success?: success?, errors?: errors?)
|
|
175
|
-
expect(KnapsackPro::Client::Connection).to receive(:new).with(action).and_return(connection).and_return(connection)
|
|
176
|
-
|
|
177
|
-
response = double
|
|
178
|
-
expect(connection).to receive(:call).and_return(response)
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
shared_examples_for 'create_build_subset method' do
|
|
182
|
-
context 'when success' do
|
|
183
|
-
let(:success?) { true }
|
|
184
|
-
|
|
185
|
-
context 'when response has errors' do
|
|
186
|
-
let(:errors?) { true }
|
|
187
|
-
|
|
188
|
-
it do
|
|
189
|
-
expect {
|
|
190
|
-
subject
|
|
191
|
-
}.to raise_error(ArgumentError)
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
context 'when response has no errors' do
|
|
196
|
-
let(:errors?) { false }
|
|
197
|
-
|
|
198
|
-
it do
|
|
199
|
-
logger = instance_double(Logger)
|
|
200
|
-
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
|
201
|
-
expect(logger).to receive(:debug).with('Saved time execution report on Knapsack Pro API server.')
|
|
202
|
-
subject
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
context 'when failure' do
|
|
208
|
-
let(:success?) { false }
|
|
209
|
-
let(:errors?) { nil }
|
|
210
|
-
|
|
211
|
-
it do
|
|
212
|
-
logger = instance_double(Logger)
|
|
213
|
-
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
|
214
|
-
expect(logger).to receive(:warn).with('Time execution report was not saved on Knapsack Pro API server due to connection problem.')
|
|
215
|
-
subject
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
context "when test files doesn't exist" do
|
|
221
|
-
let(:test_files) { [] }
|
|
222
|
-
|
|
223
|
-
it_behaves_like 'create_build_subset method'
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
context 'when test files exists' do
|
|
227
|
-
let(:test_files) { [double] }
|
|
228
|
-
|
|
229
|
-
it_behaves_like 'create_build_subset method'
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::RepositoryAdapterInitiator do
|
|
2
|
-
describe '.call' do
|
|
3
|
-
subject { described_class.call }
|
|
4
|
-
|
|
5
|
-
before do
|
|
6
|
-
expect(KnapsackPro::Config::Env).to receive(:repository_adapter).and_return(repository_adapter)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
context 'when repository adapter is git' do
|
|
10
|
-
let(:repository_adapter) { 'git' }
|
|
11
|
-
|
|
12
|
-
it { should be_instance_of KnapsackPro::RepositoryAdapters::GitAdapter }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'when default repository adapter' do
|
|
16
|
-
let(:repository_adapter) { nil }
|
|
17
|
-
|
|
18
|
-
it { should be_instance_of KnapsackPro::RepositoryAdapters::EnvAdapter }
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::RepositoryAdapters::BaseAdapter do
|
|
2
|
-
describe '#commit_hash' do
|
|
3
|
-
it do
|
|
4
|
-
expect { subject.commit_hash }.to raise_error NotImplementedError
|
|
5
|
-
end
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
describe '#branch' do
|
|
9
|
-
it do
|
|
10
|
-
expect { subject.branch }.to raise_error NotImplementedError
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::RepositoryAdapters::EnvAdapter do
|
|
2
|
-
it { should be_kind_of KnapsackPro::RepositoryAdapters::BaseAdapter }
|
|
3
|
-
|
|
4
|
-
describe '#commit_hash' do
|
|
5
|
-
let(:commit_hash) { double }
|
|
6
|
-
|
|
7
|
-
subject { described_class.new.commit_hash }
|
|
8
|
-
|
|
9
|
-
before do
|
|
10
|
-
expect(KnapsackPro::Config::Env).to receive(:commit_hash).and_return(commit_hash)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it { should eq commit_hash }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe '#branch' do
|
|
17
|
-
let(:branch) { double }
|
|
18
|
-
|
|
19
|
-
subject { described_class.new.branch }
|
|
20
|
-
|
|
21
|
-
before do
|
|
22
|
-
expect(KnapsackPro::Config::Env).to receive(:branch).and_return(branch)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it { should eq branch }
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::RepositoryAdapters::GitAdapter do
|
|
2
|
-
let!(:circle_sha1) { ENV['CIRCLE_SHA1'] }
|
|
3
|
-
let!(:circle_branch) { ENV['CIRCLE_BRANCH'] }
|
|
4
|
-
|
|
5
|
-
before do
|
|
6
|
-
stub_const('ENV', {
|
|
7
|
-
'KNAPSACK_PRO_PROJECT_DIR' => KnapsackPro.root,
|
|
8
|
-
})
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it { should be_kind_of KnapsackPro::RepositoryAdapters::BaseAdapter }
|
|
12
|
-
|
|
13
|
-
describe '#commit_hash' do
|
|
14
|
-
subject { described_class.new.commit_hash }
|
|
15
|
-
|
|
16
|
-
it { should_not be_nil }
|
|
17
|
-
its(:size) { should eq 40 }
|
|
18
|
-
it { should eq circle_sha1 } if ENV['CIRCLECI']
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe '#branch' do
|
|
22
|
-
subject { described_class.new.branch }
|
|
23
|
-
|
|
24
|
-
it { should_not be_nil }
|
|
25
|
-
it { should eq circle_branch } if ENV['CIRCLECI']
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe '#branches' do
|
|
29
|
-
subject { described_class.new.branches }
|
|
30
|
-
|
|
31
|
-
it { expect(subject.include?('main')).to be true }
|
|
32
|
-
it { expect(subject.include?(circle_branch)).to be true } if ENV['CIRCLECI']
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe '#build_author' do
|
|
36
|
-
it "returns the masked build author" do
|
|
37
|
-
allow_any_instance_of(KnapsackPro::RepositoryAdapters::GitAdapter).to receive(:git_build_author).and_return(
|
|
38
|
-
"John Doe <john.doe@example.com>" + "\n"
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
subject = KnapsackPro::RepositoryAdapters::GitAdapter.new
|
|
42
|
-
|
|
43
|
-
expect(subject.build_author).to eq 'Jo** Do* <jo**.do*@ex*****.co*>'
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context "when the command raises an exception" do
|
|
47
|
-
it "returns the no-git author" do
|
|
48
|
-
allow_any_instance_of(KnapsackPro::RepositoryAdapters::GitAdapter).to receive(:git_build_author).and_raise(Exception)
|
|
49
|
-
|
|
50
|
-
subject = KnapsackPro::RepositoryAdapters::GitAdapter.new
|
|
51
|
-
|
|
52
|
-
expect(subject.build_author).to eq "no git <no.git@example.com>"
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
context "when the command returns an empty string" do
|
|
57
|
-
it "returns the no-git author" do
|
|
58
|
-
allow_any_instance_of(KnapsackPro::RepositoryAdapters::GitAdapter).to receive(:git_build_author).and_return("")
|
|
59
|
-
|
|
60
|
-
subject = KnapsackPro::RepositoryAdapters::GitAdapter.new
|
|
61
|
-
|
|
62
|
-
expect(subject.build_author).to eq "no git <no.git@example.com>"
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
describe '#commit_authors' do
|
|
68
|
-
it "returns the masked commit authors" do
|
|
69
|
-
allow_any_instance_of(KnapsackPro::RepositoryAdapters::GitAdapter).to receive(:git_commit_authors).and_return([
|
|
70
|
-
" 5\t3v0k4 <riccardo@example.com>\n",
|
|
71
|
-
" 10\tArtur Nowak <artur@example.com>\n",
|
|
72
|
-
" 2\tRiccardo <riccardo@example.com>\n",
|
|
73
|
-
" 3 \tshadre <shadi@example.com>\n",
|
|
74
|
-
].join(""))
|
|
75
|
-
|
|
76
|
-
subject = KnapsackPro::RepositoryAdapters::GitAdapter.new
|
|
77
|
-
|
|
78
|
-
expect(subject.commit_authors).to eq([
|
|
79
|
-
{ commits: 5, author: "3v0*4 <ri******@ex*****.co*>" },
|
|
80
|
-
{ commits: 10, author: "Ar*** No*** <ar***@ex*****.co*>" },
|
|
81
|
-
{ commits: 2, author: "Ri****** <ri******@ex*****.co*>" },
|
|
82
|
-
{ commits: 3, author: "sh**** <sh***@ex*****.co*>" },
|
|
83
|
-
])
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
context "when the authors command raises an exception" do
|
|
87
|
-
it "returns []" do
|
|
88
|
-
allow_any_instance_of(KnapsackPro::RepositoryAdapters::GitAdapter).to receive(:git_commit_authors).and_raise(Exception)
|
|
89
|
-
|
|
90
|
-
subject = KnapsackPro::RepositoryAdapters::GitAdapter.new
|
|
91
|
-
|
|
92
|
-
expect(subject.commit_authors).to eq []
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
context "when the authors command returns an empty string" do
|
|
97
|
-
it "returns []" do
|
|
98
|
-
allow_any_instance_of(KnapsackPro::RepositoryAdapters::GitAdapter).to receive(:git_commit_authors).and_return("")
|
|
99
|
-
|
|
100
|
-
subject = KnapsackPro::RepositoryAdapters::GitAdapter.new
|
|
101
|
-
|
|
102
|
-
expect(subject.commit_authors).to eq []
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::Runners::BaseRunner do
|
|
2
|
-
describe '.run' do
|
|
3
|
-
it do
|
|
4
|
-
expect {
|
|
5
|
-
described_class.run(nil)
|
|
6
|
-
}.to raise_error NotImplementedError
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
describe 'instance methods' do
|
|
11
|
-
let(:adapter_class) { double }
|
|
12
|
-
let(:runner) do
|
|
13
|
-
described_class.new(adapter_class)
|
|
14
|
-
end
|
|
15
|
-
let(:allocator) { instance_double(KnapsackPro::RegularAllocator) }
|
|
16
|
-
let(:allocator_builder) { instance_double(KnapsackPro::RegularAllocatorBuilder) }
|
|
17
|
-
|
|
18
|
-
before do
|
|
19
|
-
expect(KnapsackPro::RegularAllocatorBuilder).to receive(:new).with(adapter_class).and_return(allocator_builder)
|
|
20
|
-
expect(allocator_builder).to receive(:allocator).and_return(allocator)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe '#test_file_paths' do
|
|
24
|
-
let(:test_file_paths) { double }
|
|
25
|
-
|
|
26
|
-
subject { runner.test_file_paths }
|
|
27
|
-
|
|
28
|
-
before do
|
|
29
|
-
expect(allocator).to receive(:test_file_paths).and_return(test_file_paths)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it { should eq test_file_paths }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe '#stringify_test_file_paths' do
|
|
36
|
-
let(:stringify_test_file_paths) { double }
|
|
37
|
-
|
|
38
|
-
subject { runner.stringify_test_file_paths }
|
|
39
|
-
|
|
40
|
-
before do
|
|
41
|
-
test_file_paths = double
|
|
42
|
-
expect(runner).to receive(:test_file_paths).and_return(test_file_paths)
|
|
43
|
-
expect(KnapsackPro::TestFilePresenter).to receive(:stringify_paths).with(test_file_paths).and_return(stringify_test_file_paths)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it { should eq stringify_test_file_paths }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe '#test_dir' do
|
|
50
|
-
let(:test_dir) { double }
|
|
51
|
-
|
|
52
|
-
subject { runner.test_dir }
|
|
53
|
-
|
|
54
|
-
before do
|
|
55
|
-
expect(allocator_builder).to receive(:test_dir).and_return(test_dir)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it { should eq test_dir }
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe '#test_files_to_execute_exist?' do
|
|
62
|
-
subject { runner.test_files_to_execute_exist? }
|
|
63
|
-
|
|
64
|
-
before do
|
|
65
|
-
expect(runner).to receive(:test_file_paths).and_return(test_file_paths)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
context 'when test files exists' do
|
|
69
|
-
let(:test_file_paths) { ['a_spec.rb'] }
|
|
70
|
-
|
|
71
|
-
it { should be true }
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
context "when test files doesn't exist" do
|
|
75
|
-
let(:test_file_paths) { [] }
|
|
76
|
-
|
|
77
|
-
before do
|
|
78
|
-
logger = instance_double(Logger)
|
|
79
|
-
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
|
80
|
-
expect(logger).to receive(:info).with("Knapsack Pro API returned no test files to execute for the node this time. The reason might be that you changed recently a number of total nodes or you removed some test files. Please create a new commit to get a better test suite split next time.")
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it { should be false }
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
require 'cucumber/rake/task'
|
|
2
|
-
|
|
3
|
-
describe KnapsackPro::Runners::CucumberRunner do
|
|
4
|
-
subject { described_class.new(KnapsackPro::Adapters::CucumberAdapter) }
|
|
5
|
-
|
|
6
|
-
it { should be_kind_of KnapsackPro::Runners::BaseRunner }
|
|
7
|
-
|
|
8
|
-
describe '.run' do
|
|
9
|
-
let(:args) { '--custom-arg' }
|
|
10
|
-
|
|
11
|
-
let(:test_suite_token_cucumber) { 'fake-token' }
|
|
12
|
-
|
|
13
|
-
subject { described_class.run(args) }
|
|
14
|
-
|
|
15
|
-
before do
|
|
16
|
-
expect(KnapsackPro::Config::Env).to receive(:test_suite_token_cucumber).and_return(test_suite_token_cucumber)
|
|
17
|
-
|
|
18
|
-
expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_TEST_SUITE_TOKEN', test_suite_token_cucumber)
|
|
19
|
-
expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_REGULAR_MODE_ENABLED', 'true')
|
|
20
|
-
|
|
21
|
-
expect(KnapsackPro::Config::Env).to receive(:set_test_runner_adapter).with(KnapsackPro::Adapters::CucumberAdapter)
|
|
22
|
-
|
|
23
|
-
expect(described_class).to receive(:new)
|
|
24
|
-
.with(KnapsackPro::Adapters::CucumberAdapter).and_return(runner)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context 'when test files were returned by Knapsack Pro API' do
|
|
28
|
-
let(:test_dir) { 'fake-test-dir' }
|
|
29
|
-
let(:test_file_paths) { ['features/fake1.scenario', 'features/fake2.scenario'] }
|
|
30
|
-
let(:stringify_test_file_paths) { test_file_paths.join(' ') }
|
|
31
|
-
let(:runner) do
|
|
32
|
-
instance_double(described_class,
|
|
33
|
-
test_dir: test_dir,
|
|
34
|
-
test_file_paths: test_file_paths,
|
|
35
|
-
stringify_test_file_paths: stringify_test_file_paths,
|
|
36
|
-
test_files_to_execute_exist?: true)
|
|
37
|
-
end
|
|
38
|
-
let(:task) { double }
|
|
39
|
-
|
|
40
|
-
before do
|
|
41
|
-
expect(KnapsackPro::Adapters::CucumberAdapter).to receive(:verify_bind_method_called)
|
|
42
|
-
|
|
43
|
-
tracker = instance_double(KnapsackPro::Tracker)
|
|
44
|
-
expect(KnapsackPro).to receive(:tracker).and_return(tracker)
|
|
45
|
-
expect(tracker).to receive(:set_prerun_tests).with(test_file_paths)
|
|
46
|
-
|
|
47
|
-
expect(Rake::Task).to receive(:[]).with('knapsack_pro:cucumber_run').at_least(1).and_return(task)
|
|
48
|
-
|
|
49
|
-
t = double
|
|
50
|
-
expect(Cucumber::Rake::Task).to receive(:new).with('knapsack_pro:cucumber_run').and_yield(t)
|
|
51
|
-
expect(t).to receive(:cucumber_opts=).with('--custom-arg --require fake-test-dir -- features/fake1.scenario features/fake2.scenario')
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
context 'when task already exists' do
|
|
55
|
-
before do
|
|
56
|
-
expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:cucumber_run').and_return(true)
|
|
57
|
-
expect(task).to receive(:clear)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it do
|
|
61
|
-
result = double(:result)
|
|
62
|
-
expect(task).to receive(:invoke).and_return(result)
|
|
63
|
-
expect(subject).to eq result
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
context "when task doesn't exist" do
|
|
68
|
-
before do
|
|
69
|
-
expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:cucumber_run').and_return(false)
|
|
70
|
-
expect(task).not_to receive(:clear)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it do
|
|
74
|
-
result = double(:result)
|
|
75
|
-
expect(task).to receive(:invoke).and_return(result)
|
|
76
|
-
expect(subject).to eq result
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
context 'when test files were not returned by Knapsack Pro API' do
|
|
82
|
-
let(:runner) do
|
|
83
|
-
instance_double(described_class,
|
|
84
|
-
test_files_to_execute_exist?: false)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "doesn't run tests" do
|
|
88
|
-
subject
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::Runners::MinitestRunner do
|
|
2
|
-
subject { described_class.new(KnapsackPro::Adapters::MinitestAdapter) }
|
|
3
|
-
|
|
4
|
-
it { should be_kind_of KnapsackPro::Runners::BaseRunner }
|
|
5
|
-
|
|
6
|
-
describe '.run' do
|
|
7
|
-
let(:args) { '--custom-arg' }
|
|
8
|
-
let(:task_name) { 'knapsack_pro:minitest_run' }
|
|
9
|
-
|
|
10
|
-
subject { described_class.run(args) }
|
|
11
|
-
|
|
12
|
-
before do
|
|
13
|
-
stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST' => 'minitest-token' })
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
context 'when test files were returned by Knapsack Pro API' do
|
|
17
|
-
let(:test_file_paths) { ['test_fake/a_test.rb', 'test_fake/b_test.rb'] }
|
|
18
|
-
|
|
19
|
-
before do
|
|
20
|
-
expect(KnapsackPro::Adapters::MinitestAdapter).to receive(:verify_bind_method_called)
|
|
21
|
-
|
|
22
|
-
tracker = instance_double(KnapsackPro::Tracker)
|
|
23
|
-
expect(KnapsackPro).to receive(:tracker).and_return(tracker)
|
|
24
|
-
expect(tracker).to receive(:set_prerun_tests).with(test_file_paths)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'runs tests' do
|
|
28
|
-
runner = instance_double(described_class,
|
|
29
|
-
test_dir: 'test',
|
|
30
|
-
test_file_paths: test_file_paths,
|
|
31
|
-
test_files_to_execute_exist?: true)
|
|
32
|
-
expect(described_class).to receive(:new)
|
|
33
|
-
.with(KnapsackPro::Adapters::MinitestAdapter).and_return(runner)
|
|
34
|
-
|
|
35
|
-
expect(Rake::Task.task_defined?(task_name)).to be false
|
|
36
|
-
|
|
37
|
-
subject
|
|
38
|
-
|
|
39
|
-
expect(Rake::Task.task_defined?(task_name)).to be true
|
|
40
|
-
|
|
41
|
-
expect(ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN']).to eq 'minitest-token'
|
|
42
|
-
expect(ENV['KNAPSACK_PRO_REGULAR_MODE_ENABLED']).to eq 'true'
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'when test files were not returned by Knapsack Pro API' do
|
|
47
|
-
it "doesn't run tests" do
|
|
48
|
-
runner = instance_double(described_class,
|
|
49
|
-
test_files_to_execute_exist?: false)
|
|
50
|
-
expect(described_class).to receive(:new)
|
|
51
|
-
.with(KnapsackPro::Adapters::MinitestAdapter).and_return(runner)
|
|
52
|
-
|
|
53
|
-
subject
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|