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,62 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::Runners::TestUnitRunner do
|
|
2
|
-
subject { described_class.new(KnapsackPro::Adapters::TestUnitAdapter) }
|
|
3
|
-
|
|
4
|
-
it { should be_kind_of KnapsackPro::Runners::BaseRunner }
|
|
5
|
-
|
|
6
|
-
describe '.run' do
|
|
7
|
-
let(:args) { '--verbose --order=random' }
|
|
8
|
-
|
|
9
|
-
subject { described_class.run(args) }
|
|
10
|
-
|
|
11
|
-
before do
|
|
12
|
-
stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT' => 'test-unit-token' })
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'when test files were returned by Knapsack Pro API' do
|
|
16
|
-
let(:test_file_paths) { ['test-unit_fake/a_test.rb', 'test-unit_fake/b_test.rb'] }
|
|
17
|
-
|
|
18
|
-
it 'runs tests' do
|
|
19
|
-
expect(KnapsackPro::Adapters::TestUnitAdapter).to receive(:verify_bind_method_called)
|
|
20
|
-
|
|
21
|
-
tracker = instance_double(KnapsackPro::Tracker)
|
|
22
|
-
expect(KnapsackPro).to receive(:tracker).and_return(tracker)
|
|
23
|
-
expect(tracker).to receive(:set_prerun_tests).with(test_file_paths)
|
|
24
|
-
|
|
25
|
-
runner = instance_double(described_class,
|
|
26
|
-
test_dir: 'test-unit_fake',
|
|
27
|
-
test_file_paths: test_file_paths,
|
|
28
|
-
test_files_to_execute_exist?: true)
|
|
29
|
-
expect(described_class).to receive(:new)
|
|
30
|
-
.with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner)
|
|
31
|
-
|
|
32
|
-
auto_runner_exit_code = 0
|
|
33
|
-
expect(described_class).to receive(:test_unit_autorunner_run) do |flag, test_dir, cli_args|
|
|
34
|
-
expect(flag).to be true
|
|
35
|
-
expect(test_dir).to eq 'test-unit_fake'
|
|
36
|
-
expect(cli_args.size).to eq 4
|
|
37
|
-
expect(cli_args[0]).to eq '--verbose'
|
|
38
|
-
expect(cli_args[1]).to eq '--order=random'
|
|
39
|
-
expect(cli_args[2]).to end_with 'test-unit_fake/a_test.rb'
|
|
40
|
-
expect(cli_args[3]).to end_with 'test-unit_fake/b_test.rb'
|
|
41
|
-
end.and_return(auto_runner_exit_code)
|
|
42
|
-
expect(described_class).to receive(:exit).with(auto_runner_exit_code)
|
|
43
|
-
|
|
44
|
-
subject
|
|
45
|
-
|
|
46
|
-
expect(ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN']).to eq 'test-unit-token'
|
|
47
|
-
expect(ENV['KNAPSACK_PRO_REGULAR_MODE_ENABLED']).to eq 'true'
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context 'when test files were not returned by Knapsack Pro API' do
|
|
52
|
-
it "doesn't run tests" do
|
|
53
|
-
runner = instance_double(described_class,
|
|
54
|
-
test_files_to_execute_exist?: false)
|
|
55
|
-
expect(described_class).to receive(:new)
|
|
56
|
-
.with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner)
|
|
57
|
-
|
|
58
|
-
subject
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::SlowTestFileDeterminer do
|
|
2
|
-
describe '.call' do
|
|
3
|
-
let(:node_total) { 4 }
|
|
4
|
-
|
|
5
|
-
before do
|
|
6
|
-
expect(KnapsackPro::Config::Env).to receive(:ci_node_total).and_return(node_total)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
subject { described_class.call(test_files) }
|
|
10
|
-
|
|
11
|
-
context 'when test files have recorded execution time' do
|
|
12
|
-
let(:test_files) do
|
|
13
|
-
[
|
|
14
|
-
{ 'path' => 'a_spec.rb', 'time_execution' => 1.0 },
|
|
15
|
-
{ 'path' => 'b_spec.rb', 'time_execution' => 3.4 },
|
|
16
|
-
{ 'path' => 'c_spec.rb', 'time_execution' => 3.5 },
|
|
17
|
-
{ 'path' => 'd_spec.rb', 'time_execution' => 12.1 },
|
|
18
|
-
]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it 'detects slow tests above 3.5s threshold (20.0 / 4 nodes * 70% threshold = 3.5)' do
|
|
22
|
-
expect(subject).to eq([
|
|
23
|
-
{ 'path' => 'c_spec.rb', 'time_execution' => 3.5 },
|
|
24
|
-
{ 'path' => 'd_spec.rb', 'time_execution' => 12.1 },
|
|
25
|
-
])
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context 'when test files have recorded execution time AND slow test files threshold is set' do
|
|
30
|
-
let(:test_files) do
|
|
31
|
-
[
|
|
32
|
-
{ 'path' => 'a_spec.rb', 'time_execution' => 1.0 },
|
|
33
|
-
{ 'path' => 'b_spec.rb', 'time_execution' => 3.4 },
|
|
34
|
-
{ 'path' => 'c_spec.rb', 'time_execution' => 3.5 },
|
|
35
|
-
{ 'path' => 'd_spec.rb', 'time_execution' => 12.1 },
|
|
36
|
-
]
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
before do
|
|
40
|
-
stub_const("ENV", { 'KNAPSACK_PRO_SLOW_TEST_FILE_THRESHOLD' => '2' })
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'detects slow tests above 2.0s threshold' do
|
|
44
|
-
expect(subject).to eq([
|
|
45
|
-
{ 'path' => 'b_spec.rb', 'time_execution' => 3.4 },
|
|
46
|
-
{ 'path' => 'c_spec.rb', 'time_execution' => 3.5 },
|
|
47
|
-
{ 'path' => 'd_spec.rb', 'time_execution' => 12.1 },
|
|
48
|
-
])
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context 'when test files have no recorded execution time' do
|
|
53
|
-
let(:test_files) do
|
|
54
|
-
[
|
|
55
|
-
{ 'path' => 'a_spec.rb', 'time_execution' => 0.0 },
|
|
56
|
-
{ 'path' => 'b_spec.rb', 'time_execution' => 0.0 },
|
|
57
|
-
]
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it do
|
|
61
|
-
expect(subject).to eq([])
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
context 'when there are no test files' do
|
|
66
|
-
let(:test_files) { [] }
|
|
67
|
-
|
|
68
|
-
it do
|
|
69
|
-
expect(subject).to eq([])
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe '.save_to_json_report', :clear_tmp do
|
|
75
|
-
let(:json_report_path) { '.knapsack_pro/slow_test_file_determiner/slow_test_files_node_0.json' }
|
|
76
|
-
let(:test_files) do
|
|
77
|
-
[
|
|
78
|
-
{ 'path' => 'a_spec.rb', 'time_execution' => 1.0 },
|
|
79
|
-
# unique path to ensure we saved on disk a completely new report
|
|
80
|
-
{ 'path' => "#{SecureRandom.hex}_spec.rb", 'time_execution' => 3.4 },
|
|
81
|
-
]
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
subject { described_class.save_to_json_report(test_files) }
|
|
85
|
-
|
|
86
|
-
it do
|
|
87
|
-
subject
|
|
88
|
-
expect(File.read(json_report_path)).to eq(test_files.to_json)
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
describe '.read_from_json_report', :clear_tmp do
|
|
93
|
-
let(:test_files) do
|
|
94
|
-
[
|
|
95
|
-
{ 'path' => 'a_spec.rb', 'time_execution' => 1.0 },
|
|
96
|
-
# unique path to ensure we saved on disk a completely new report
|
|
97
|
-
{ 'path' => "#{SecureRandom.hex}_spec.rb", 'time_execution' => 3.4 },
|
|
98
|
-
]
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
subject { described_class.read_from_json_report }
|
|
102
|
-
|
|
103
|
-
context 'when json report exists' do
|
|
104
|
-
before do
|
|
105
|
-
described_class.save_to_json_report(test_files)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it do
|
|
109
|
-
expect(subject).to eq test_files
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
context 'when json report does not exist' do
|
|
114
|
-
it do
|
|
115
|
-
expect { subject }.to raise_error(RuntimeError, 'The report with slow test files has not been generated yet. If you have enabled split by test cases https://knapsackpro.com/perma/ruby/split-by-test-examples and you see this error it means that your tests accidentally cleaned up the .knapsack_pro directory. Please do not remove this directory during tests runtime!')
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::SlowTestFileFinder do
|
|
2
|
-
describe '.call' do
|
|
3
|
-
let(:adapter_class) { double }
|
|
4
|
-
|
|
5
|
-
subject { described_class.call(adapter_class) }
|
|
6
|
-
|
|
7
|
-
before do
|
|
8
|
-
expect(KnapsackPro::Config::Env).to receive(:test_files_encrypted?).and_return(test_files_encrypted?)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
context 'when test files are not encrypted' do
|
|
12
|
-
let(:test_files_encrypted?) { false }
|
|
13
|
-
|
|
14
|
-
it do
|
|
15
|
-
test_files_from_api = double
|
|
16
|
-
build_distribution_entity = instance_double(KnapsackPro::BuildDistributionFetcher::BuildDistributionEntity, test_files: test_files_from_api)
|
|
17
|
-
expect(KnapsackPro::BuildDistributionFetcher).to receive(:call).and_return(build_distribution_entity)
|
|
18
|
-
|
|
19
|
-
merged_test_files_from_api = double
|
|
20
|
-
expect(KnapsackPro::TestCaseMergers::BaseMerger).to receive(:call).with(adapter_class, test_files_from_api).and_return(merged_test_files_from_api)
|
|
21
|
-
|
|
22
|
-
test_files_existing_on_disk = double
|
|
23
|
-
expect(KnapsackPro::TestFileFinder).to receive(:select_test_files_that_can_be_run).with(adapter_class, merged_test_files_from_api).and_return(test_files_existing_on_disk)
|
|
24
|
-
|
|
25
|
-
slow_test_files = double
|
|
26
|
-
expect(KnapsackPro::SlowTestFileDeterminer).to receive(:call).with(test_files_existing_on_disk).and_return(slow_test_files)
|
|
27
|
-
|
|
28
|
-
expect(KnapsackPro::SlowTestFileDeterminer).to receive(:save_to_json_report).with(slow_test_files)
|
|
29
|
-
|
|
30
|
-
expect(subject).to eq slow_test_files
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context 'when test files are encrypted' do
|
|
35
|
-
let(:test_files_encrypted?) { true }
|
|
36
|
-
|
|
37
|
-
it do
|
|
38
|
-
expect { subject }.to raise_error RuntimeError, 'Split by test cases is not possible when you have enabled test file names encryption ( https://knapsackpro.com/perma/ruby/encryption ). You need to disable encryption with KNAPSACK_PRO_TEST_FILES_ENCRYPTED=false in order to use split by test cases https://knapsackpro.com/perma/ruby/split-by-test-examples'
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::TaskLoader do
|
|
2
|
-
describe '#load_tasks' do
|
|
3
|
-
let(:rspec_rake_task_path) { "#{KnapsackPro.root}/lib/tasks/rspec.rake" }
|
|
4
|
-
let(:cucumber_rake_task_path) { "#{KnapsackPro.root}/lib/tasks/cucumber.rake" }
|
|
5
|
-
let(:minitest_rake_task_path) { "#{KnapsackPro.root}/lib/tasks/minitest.rake" }
|
|
6
|
-
|
|
7
|
-
before { allow(subject).to receive(:import) }
|
|
8
|
-
after { subject.load_tasks }
|
|
9
|
-
|
|
10
|
-
it { expect(subject).to receive(:import).with(rspec_rake_task_path) }
|
|
11
|
-
it { expect(subject).to receive(:import).with(cucumber_rake_task_path) }
|
|
12
|
-
it { expect(subject).to receive(:import).with(minitest_rake_task_path) }
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector do
|
|
2
|
-
let(:report_dir) { '.knapsack_pro/test_case_detectors/rspec' }
|
|
3
|
-
let(:report_path) { '.knapsack_pro/test_case_detectors/rspec/rspec_dry_run_json_report_node_0.json' }
|
|
4
|
-
let(:rspec_test_example_detector) { described_class.new }
|
|
5
|
-
|
|
6
|
-
describe '#generate_json_report' do
|
|
7
|
-
subject { rspec_test_example_detector.generate_json_report(rspec_args) }
|
|
8
|
-
|
|
9
|
-
shared_examples 'generate_json_report runs RSpec::Core::Runner' do
|
|
10
|
-
before do
|
|
11
|
-
expect(KnapsackPro::Config::TempFiles).to receive(:ensure_temp_directory_exists!)
|
|
12
|
-
|
|
13
|
-
expect(FileUtils).to receive(:mkdir_p).with(report_dir)
|
|
14
|
-
|
|
15
|
-
allow(File).to receive(:exist?)
|
|
16
|
-
expect(File).to receive(:exist?).at_least(:once).with(report_path).and_return(true)
|
|
17
|
-
expect(File).to receive(:delete).with(report_path)
|
|
18
|
-
|
|
19
|
-
expect(rspec_test_example_detector).to receive(:slow_test_files).and_return(test_file_entities)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
context 'when there are no slow test files' do
|
|
23
|
-
let(:test_file_entities) { [] }
|
|
24
|
-
|
|
25
|
-
before do
|
|
26
|
-
expect(File).to receive(:write).with(report_path, { examples: [] }.to_json)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it do
|
|
30
|
-
expect(subject).to be_nil
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context 'when slow test files exist' do
|
|
35
|
-
let(:test_file_entities) do
|
|
36
|
-
[
|
|
37
|
-
{ 'path' => 'spec/a_spec.rb' },
|
|
38
|
-
{ 'path' => 'spec/b_spec.rb' },
|
|
39
|
-
]
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
before do
|
|
43
|
-
test_dir = 'spec'
|
|
44
|
-
expect(KnapsackPro::Config::Env).to receive(:test_dir).and_return(nil)
|
|
45
|
-
expect(KnapsackPro::TestFilePattern).to receive(:test_dir).with(KnapsackPro::Adapters::RSpecAdapter).and_return(test_dir)
|
|
46
|
-
|
|
47
|
-
options = double
|
|
48
|
-
expect(RSpec::Core::ConfigurationOptions).to receive(:new).with(expected_args + [
|
|
49
|
-
'--format', expected_format,
|
|
50
|
-
'--dry-run',
|
|
51
|
-
'--out', report_path,
|
|
52
|
-
'--default-path', test_dir,
|
|
53
|
-
'spec/a_spec.rb', 'spec/b_spec.rb',
|
|
54
|
-
]).and_return(options)
|
|
55
|
-
|
|
56
|
-
rspec_core_runner = double
|
|
57
|
-
expect(RSpec::Core::Runner).to receive(:new).with(options).and_return(rspec_core_runner)
|
|
58
|
-
expect(rspec_core_runner).to receive(:run).with($stderr, $stdout).and_return(exit_code)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
context 'when exit code from RSpec::Core::Runner is 0' do
|
|
62
|
-
let(:exit_code) { 0 }
|
|
63
|
-
|
|
64
|
-
it do
|
|
65
|
-
expect(subject).to be_nil
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
context 'when exit code from RSpec::Core::Runner is 1' do
|
|
70
|
-
let(:exit_code) { 1 }
|
|
71
|
-
|
|
72
|
-
before do
|
|
73
|
-
json_file = %{
|
|
74
|
-
{"version":"3.11.0","messages":["An error occurred while loading ./spec/a_spec.rb"],"examples":[],"summary":{"duration":3.6e-05,"example_count":0,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":1},"summary_line":"0 examples, 0 failures, 1 error occurred outside of examples"}
|
|
75
|
-
}.strip
|
|
76
|
-
expect(File).to receive(:read).with(report_path).and_return(json_file)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it do
|
|
80
|
-
expect { subject }.to raise_error(SystemExit) { |error| expect(error.status).to eq exit_code }
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
context 'when RSpec >= 3.6.0' do
|
|
87
|
-
let(:rspec_args) { '' }
|
|
88
|
-
let(:expected_args) { [] }
|
|
89
|
-
let(:expected_format) { 'json' }
|
|
90
|
-
|
|
91
|
-
it_behaves_like 'generate_json_report runs RSpec::Core::Runner'
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
context 'when RSpec < 3.6.0' do
|
|
95
|
-
let(:rspec_args) { '' }
|
|
96
|
-
let(:expected_args) { [] }
|
|
97
|
-
let(:expected_format) { 'KnapsackPro::Formatters::RSpecJsonFormatter' }
|
|
98
|
-
|
|
99
|
-
before do
|
|
100
|
-
stub_const('RSpec::Core::Version::STRING', '3.5.0')
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it_behaves_like 'generate_json_report runs RSpec::Core::Runner'
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
context 'when RSpec CLI args are present including format option' do
|
|
107
|
-
let(:rspec_args) { '-t mytag --format documentation --out /tmp/documentation.txt --tag ~@skip --example-matches regexp --example string' }
|
|
108
|
-
let(:expected_args) { ['-t', 'mytag', '--tag', '~@skip', '--example-matches', 'regexp', '--example', 'string'] }
|
|
109
|
-
let(:expected_format) { 'json' }
|
|
110
|
-
|
|
111
|
-
describe 'removes formatters from RSpec CLI args' do
|
|
112
|
-
it_behaves_like 'generate_json_report runs RSpec::Core::Runner'
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
context 'when RSpec CLI args are not set' do
|
|
117
|
-
let(:rspec_args) { nil }
|
|
118
|
-
let(:expected_args) { [] }
|
|
119
|
-
let(:expected_format) { 'json' }
|
|
120
|
-
|
|
121
|
-
it do
|
|
122
|
-
expect { subject }.to raise_error("The internal KNAPSACK_PRO_RSPEC_OPTIONS environment variable is unset. Ensure it is not overridden accidentally. Otherwise, please report this as a bug: https://knapsackpro.com/perma/ruby/support")
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
context 'with --force-color' do
|
|
127
|
-
let(:rspec_args) { '--force-color' }
|
|
128
|
-
let(:expected_args) { ['--force-color'] }
|
|
129
|
-
let(:expected_format) { 'json' }
|
|
130
|
-
|
|
131
|
-
it_behaves_like 'generate_json_report runs RSpec::Core::Runner'
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
context 'with --no-color and --force-color' do
|
|
135
|
-
let(:rspec_args) { '--no-color --force-color' }
|
|
136
|
-
|
|
137
|
-
after { KnapsackPro.reset_logger! }
|
|
138
|
-
|
|
139
|
-
it do
|
|
140
|
-
subject_class = Class.new(KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector) do
|
|
141
|
-
define_method(:slow_test_files) do
|
|
142
|
-
[{ 'path' => 'spec/a_spec.rb' }]
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
expect do
|
|
147
|
-
KnapsackPro.logger = ::Logger.new($stdout)
|
|
148
|
-
subject_class.new.generate_json_report(rspec_args)
|
|
149
|
-
end
|
|
150
|
-
.to output(/Please only use one of `--force-color` and `--no-color`/).to_stderr
|
|
151
|
-
.and output(%r{ERROR -- knapsack_pro: Failed to generate the slow test files report: bundle exec rspec --no-color --force-color --format json --dry-run --out .knapsack_pro/test_case_detectors/rspec/rspec_dry_run_json_report_node_0.json --default-path spec spec/a_spec.rb}).to_stdout
|
|
152
|
-
.and raise_error(SystemExit) { |error| expect(error.status).to eq 1 }
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
describe '#test_file_example_paths' do
|
|
158
|
-
subject { described_class.new.test_file_example_paths }
|
|
159
|
-
|
|
160
|
-
context 'when JSON report exists' do
|
|
161
|
-
it do
|
|
162
|
-
expect(File).to receive(:exist?).with(report_path).and_return(true)
|
|
163
|
-
|
|
164
|
-
json_file = {
|
|
165
|
-
'examples' => [
|
|
166
|
-
{ id: './spec/a_spec.rb[1:1]' },
|
|
167
|
-
{ id: './spec/a_spec.rb[1:2]' },
|
|
168
|
-
]
|
|
169
|
-
}.to_json
|
|
170
|
-
expect(File).to receive(:read).with(report_path).and_return(json_file)
|
|
171
|
-
|
|
172
|
-
expect(subject).to eq([
|
|
173
|
-
{ 'path' => 'spec/a_spec.rb[1:1]' },
|
|
174
|
-
{ 'path' => 'spec/a_spec.rb[1:2]' },
|
|
175
|
-
])
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
context 'when JSON report does not exist' do
|
|
180
|
-
it do
|
|
181
|
-
expect(File).to receive(:exist?).with(report_path).and_return(false)
|
|
182
|
-
|
|
183
|
-
expect { subject }.to raise_error(RuntimeError, "No report found at .knapsack_pro/test_case_detectors/rspec/rspec_dry_run_json_report_node_0.json")
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
describe '#slow_test_files' do
|
|
189
|
-
subject { described_class.new.slow_test_files }
|
|
190
|
-
|
|
191
|
-
before do
|
|
192
|
-
expect(KnapsackPro::Config::Env).to receive(:slow_test_file_pattern).and_return(slow_test_file_pattern)
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
context 'when slow test file pattern is present' do
|
|
196
|
-
let(:slow_test_file_pattern) { double }
|
|
197
|
-
|
|
198
|
-
it do
|
|
199
|
-
expected_slow_test_files = double
|
|
200
|
-
expect(KnapsackPro::TestFileFinder).to receive(:slow_test_files_by_pattern).with(KnapsackPro::Adapters::RSpecAdapter).and_return(expected_slow_test_files)
|
|
201
|
-
|
|
202
|
-
expect(subject).to eq expected_slow_test_files
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
context 'when slow test file pattern is not present' do
|
|
207
|
-
let(:slow_test_file_pattern) { nil }
|
|
208
|
-
|
|
209
|
-
it do
|
|
210
|
-
expected_slow_test_files = double
|
|
211
|
-
expect(KnapsackPro::SlowTestFileDeterminer).to receive(:read_from_json_report).and_return(expected_slow_test_files)
|
|
212
|
-
|
|
213
|
-
expect(subject).to eq expected_slow_test_files
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::TestCaseMergers::BaseMerger do
|
|
2
|
-
describe '.call' do
|
|
3
|
-
let(:test_files) { double }
|
|
4
|
-
|
|
5
|
-
subject { described_class.call(adapter_class, test_files) }
|
|
6
|
-
|
|
7
|
-
context 'when adapter_class is KnapsackPro::Adapters::RSpecAdapter' do
|
|
8
|
-
let(:adapter_class) { KnapsackPro::Adapters::RSpecAdapter }
|
|
9
|
-
|
|
10
|
-
it do
|
|
11
|
-
result = double
|
|
12
|
-
rspec_merger = instance_double(KnapsackPro::TestCaseMergers::RSpecMerger, call: result)
|
|
13
|
-
expect(KnapsackPro::TestCaseMergers::RSpecMerger).to receive(:new).with(test_files).and_return(rspec_merger)
|
|
14
|
-
|
|
15
|
-
expect(subject).to eq result
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context 'when adapter_class is unknown' do
|
|
20
|
-
let(:adapter_class) { 'fake-adapter' }
|
|
21
|
-
|
|
22
|
-
it do
|
|
23
|
-
expect { subject }.to raise_error 'Test case merger does not exist for adapter_class: fake-adapter'
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::TestCaseMergers::RSpecMerger do
|
|
2
|
-
describe '#call' do
|
|
3
|
-
subject { described_class.new(test_files).call }
|
|
4
|
-
|
|
5
|
-
context 'when test files are regular file paths (not test example paths)' do
|
|
6
|
-
let(:test_files) do
|
|
7
|
-
[
|
|
8
|
-
{ 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
|
|
9
|
-
{ 'path' => 'spec/b_spec.rb', 'time_execution' => 2.2 },
|
|
10
|
-
]
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it 'returns the test files unchanged' do
|
|
14
|
-
expect(subject).to eq([
|
|
15
|
-
{ 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
|
|
16
|
-
{ 'path' => 'spec/b_spec.rb', 'time_execution' => 2.2 },
|
|
17
|
-
])
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context 'when test files have test example paths' do
|
|
22
|
-
let(:test_files) do
|
|
23
|
-
[
|
|
24
|
-
{ 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
|
|
25
|
-
# test example paths
|
|
26
|
-
{ 'path' => 'spec/test_case_spec.rb[1:1]', 'time_execution' => 2.2 },
|
|
27
|
-
{ 'path' => 'spec/test_case_spec.rb[1:2]', 'time_execution' => 0.8 },
|
|
28
|
-
]
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it 'merges the test example paths and sums their execution times' do
|
|
32
|
-
expect(subject).to eq([
|
|
33
|
-
{ 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
|
|
34
|
-
{ 'path' => 'spec/test_case_spec.rb', 'time_execution' => 3.0 },
|
|
35
|
-
])
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context 'when test files have test example paths and the full test file path exists simultaneously' do
|
|
40
|
-
context 'when the full test file path has a higher execution time than the sum of test example paths' do
|
|
41
|
-
let(:test_files) do
|
|
42
|
-
[
|
|
43
|
-
{ 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
|
|
44
|
-
# full test file path exists alongside test example paths
|
|
45
|
-
{ 'path' => 'spec/test_case_spec.rb', 'time_execution' => 3.1 },
|
|
46
|
-
# test example paths
|
|
47
|
-
{ 'path' => 'spec/test_case_spec.rb[1:1]', 'time_execution' => 2.2 },
|
|
48
|
-
{ 'path' => 'spec/test_case_spec.rb[1:2]', 'time_execution' => 0.8 },
|
|
49
|
-
]
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it 'returns the full test file path execution time' do
|
|
53
|
-
expect(subject).to eq([
|
|
54
|
-
{ 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
|
|
55
|
-
{ 'path' => 'spec/test_case_spec.rb', 'time_execution' => 3.1 },
|
|
56
|
-
])
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context 'when the full test file path has a lower execution time than the sum of test example paths' do
|
|
61
|
-
let(:test_files) do
|
|
62
|
-
[
|
|
63
|
-
{ 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
|
|
64
|
-
# full test file path exists alongside test example paths
|
|
65
|
-
{ 'path' => 'spec/test_case_spec.rb', 'time_execution' => 2.9 },
|
|
66
|
-
# test example paths
|
|
67
|
-
{ 'path' => 'spec/test_case_spec.rb[1:1]', 'time_execution' => 2.2 },
|
|
68
|
-
{ 'path' => 'spec/test_case_spec.rb[1:2]', 'time_execution' => 0.8 },
|
|
69
|
-
]
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "returns the sum of test example paths' execution times" do
|
|
73
|
-
expect(subject).to eq([
|
|
74
|
-
{ 'path' => 'spec/a_spec.rb', 'time_execution' => 1.1 },
|
|
75
|
-
{ 'path' => 'spec/test_case_spec.rb', 'time_execution' => 3.0 },
|
|
76
|
-
])
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::TestFileCleaner do
|
|
2
|
-
describe '.clean' do
|
|
3
|
-
let(:test_file_path) { './models/user_spec.rb' }
|
|
4
|
-
|
|
5
|
-
subject { described_class.clean(test_file_path) }
|
|
6
|
-
|
|
7
|
-
it 'removes ./ from the begining of the test file path' do
|
|
8
|
-
expect(subject).to eq 'models/user_spec.rb'
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|