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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/knapsack_pro/adapters/minitest_adapter.rb +8 -13
  3. data/lib/knapsack_pro/client/connection.rb +1 -1
  4. data/lib/knapsack_pro/config/env.rb +1 -24
  5. data/lib/knapsack_pro/version.rb +1 -1
  6. metadata +2 -196
  7. data/.circleci/config.yml +0 -468
  8. data/.github/assets/install-button.png +0 -0
  9. data/.github/assets/knapsack-diamonds.png +0 -0
  10. data/.github/dependabot.yml +0 -11
  11. data/.github/pull_request_template.md +0 -11
  12. data/.gitignore +0 -39
  13. data/.rspec +0 -5
  14. data/CHANGELOG.md +0 -1995
  15. data/Gemfile +0 -13
  16. data/LICENSE +0 -22
  17. data/README.md +0 -90
  18. data/Rakefile +0 -2
  19. data/knapsack_pro.gemspec +0 -43
  20. data/spec/fixtures/test_file_list_source_file.txt +0 -6
  21. data/spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/invalid_test_suite_token.yml +0 -59
  22. data/spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/success.yml +0 -61
  23. data/spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/invalid_test_suite_token.yml +0 -50
  24. data/spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/success.yml +0 -50
  25. data/spec/integration/api/build_distributions_subset_spec.rb +0 -77
  26. data/spec/integration/api/build_subsets_create_spec.rb +0 -77
  27. data/spec/integration/runners/fallback_spec.rb +0 -131
  28. data/spec/integration/runners/queue/cucumber_runner_fallback_spec.rb +0 -129
  29. data/spec/integration/runners/queue/minitest_runner_fallback_spec.rb +0 -129
  30. data/spec/integration/runners/queue/rspec_runner.rb +0 -80
  31. data/spec/integration/runners/queue/rspec_runner_fallback_spec.rb +0 -137
  32. data/spec/integration/runners/queue/rspec_runner_spec.rb +0 -2672
  33. data/spec/knapsack_pro/adapters/base_adapter_spec.rb +0 -221
  34. data/spec/knapsack_pro/adapters/cucumber_adapter_spec.rb +0 -216
  35. data/spec/knapsack_pro/adapters/minitest_adapter_spec.rb +0 -189
  36. data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +0 -427
  37. data/spec/knapsack_pro/adapters/spinach_adapter_spec.rb +0 -61
  38. data/spec/knapsack_pro/adapters/test_unit_adapter_spec.rb +0 -86
  39. data/spec/knapsack_pro/base_allocator_builder_spec.rb +0 -102
  40. data/spec/knapsack_pro/build_distribution_fetcher_spec.rb +0 -89
  41. data/spec/knapsack_pro/client/api/action_spec.rb +0 -17
  42. data/spec/knapsack_pro/client/api/v1/base_spec.rb +0 -2
  43. data/spec/knapsack_pro/client/api/v1/build_distributions_spec.rb +0 -95
  44. data/spec/knapsack_pro/client/api/v1/build_subsets_spec.rb +0 -35
  45. data/spec/knapsack_pro/client/api/v1/queues_spec.rb +0 -83
  46. data/spec/knapsack_pro/client/connection_spec.rb +0 -581
  47. data/spec/knapsack_pro/config/ci/app_veyor_spec.rb +0 -87
  48. data/spec/knapsack_pro/config/ci/base_spec.rb +0 -10
  49. data/spec/knapsack_pro/config/ci/buildkite_spec.rb +0 -135
  50. data/spec/knapsack_pro/config/ci/circle_spec.rb +0 -122
  51. data/spec/knapsack_pro/config/ci/cirrus_ci_spec.rb +0 -87
  52. data/spec/knapsack_pro/config/ci/codefresh_spec.rb +0 -81
  53. data/spec/knapsack_pro/config/ci/codeship_spec.rb +0 -80
  54. data/spec/knapsack_pro/config/ci/github_actions_spec.rb +0 -140
  55. data/spec/knapsack_pro/config/ci/gitlab_ci_spec.rb +0 -137
  56. data/spec/knapsack_pro/config/ci/heroku_spec.rb +0 -87
  57. data/spec/knapsack_pro/config/ci/semaphore2_spec.rb +0 -133
  58. data/spec/knapsack_pro/config/ci/semaphore_spec.rb +0 -87
  59. data/spec/knapsack_pro/config/ci/travis_spec.rb +0 -73
  60. data/spec/knapsack_pro/config/env_generator_spec.rb +0 -52
  61. data/spec/knapsack_pro/config/env_spec.rb +0 -1291
  62. data/spec/knapsack_pro/config/temp_files_spec.rb +0 -25
  63. data/spec/knapsack_pro/crypto/branch_encryptor_spec.rb +0 -53
  64. data/spec/knapsack_pro/crypto/decryptor_spec.rb +0 -83
  65. data/spec/knapsack_pro/crypto/digestor_spec.rb +0 -13
  66. data/spec/knapsack_pro/crypto/encryptor_spec.rb +0 -58
  67. data/spec/knapsack_pro/formatters/time_tracker_fetcher_spec.rb +0 -27
  68. data/spec/knapsack_pro/formatters/time_tracker_spec.rb +0 -448
  69. data/spec/knapsack_pro/hooks/queue_spec.rb +0 -199
  70. data/spec/knapsack_pro/presenter_spec.rb +0 -57
  71. data/spec/knapsack_pro/pure/queue/rspec_pure_spec.rb +0 -248
  72. data/spec/knapsack_pro/queue_spec.rb +0 -35
  73. data/spec/knapsack_pro/report_spec.rb +0 -232
  74. data/spec/knapsack_pro/repository_adapter_initiator_spec.rb +0 -21
  75. data/spec/knapsack_pro/repository_adapters/base_adapter_spec.rb +0 -13
  76. data/spec/knapsack_pro/repository_adapters/env_adapter_spec.rb +0 -27
  77. data/spec/knapsack_pro/repository_adapters/git_adapter_spec.rb +0 -106
  78. data/spec/knapsack_pro/runners/base_runner_spec.rb +0 -87
  79. data/spec/knapsack_pro/runners/cucumber_runner_spec.rb +0 -92
  80. data/spec/knapsack_pro/runners/minitest_runner_spec.rb +0 -57
  81. data/spec/knapsack_pro/runners/queue/base_runner_spec.rb +0 -73
  82. data/spec/knapsack_pro/runners/queue/cucumber_runner_spec.rb +0 -209
  83. data/spec/knapsack_pro/runners/queue/minitest_runner_spec.rb +0 -203
  84. data/spec/knapsack_pro/runners/rspec_runner_spec.rb +0 -111
  85. data/spec/knapsack_pro/runners/spinach_runner_spec.rb +0 -56
  86. data/spec/knapsack_pro/runners/test_unit_runner_spec.rb +0 -62
  87. data/spec/knapsack_pro/slow_test_file_determiner_spec.rb +0 -119
  88. data/spec/knapsack_pro/slow_test_file_finder_spec.rb +0 -42
  89. data/spec/knapsack_pro/task_loader_spec.rb +0 -14
  90. data/spec/knapsack_pro/test_case_detectors/rspec_test_example_detector_spec.rb +0 -217
  91. data/spec/knapsack_pro/test_case_mergers/base_merger_spec.rb +0 -27
  92. data/spec/knapsack_pro/test_case_mergers/rspec_merger_spec.rb +0 -81
  93. data/spec/knapsack_pro/test_file_cleaner_spec.rb +0 -11
  94. data/spec/knapsack_pro/test_file_finder_spec.rb +0 -176
  95. data/spec/knapsack_pro/test_file_pattern_spec.rb +0 -49
  96. data/spec/knapsack_pro/test_file_presenter_spec.rb +0 -22
  97. data/spec/knapsack_pro/test_files_with_test_cases_composer_spec.rb +0 -41
  98. data/spec/knapsack_pro/test_flat_distributor_spec.rb +0 -60
  99. data/spec/knapsack_pro/tracker_spec.rb +0 -184
  100. data/spec/knapsack_pro/utils_spec.rb +0 -55
  101. data/spec/knapsack_pro_spec.rb +0 -116
  102. data/spec/spec_helper.rb +0 -47
  103. data/spec/support/.gitkeep +0 -0
  104. data/spec/support/fakes/cucumber.rb +0 -25
  105. data/spec/support/fakes/minitest.rb +0 -18
  106. data/spec/support/shared_examples/adapter.rb +0 -17
  107. data/spec_fake/controllers/users_controller_spec.rb +0 -0
  108. data/spec_fake/models/admin_spec.rb +0 -0
  109. data/spec_fake/models/user_spec.rb +0 -0
  110. data/spec_fake/spec_helper.rb +0 -0
  111. data/spec_time_tracker/spec_helper.rb +0 -29
  112. data/test_fake/a_test.rb +0 -0
  113. data/test_fake/b_test.rb +0 -0
@@ -1,176 +0,0 @@
1
- describe KnapsackPro::TestFileFinder do
2
- describe '.call' do
3
- let(:test_file_pattern) { double }
4
- let(:test_files) { double }
5
-
6
- subject { described_class.call(test_file_pattern) }
7
-
8
- before do
9
- test_file_finder = instance_double(described_class, call: test_files)
10
- expect(described_class).to receive(:new).with(test_file_pattern, true).and_return(test_file_finder)
11
- end
12
-
13
- it { should eq test_files }
14
- end
15
-
16
- describe '.slow_test_files_by_pattern' do
17
- let(:adapter_class) { double }
18
-
19
- subject { described_class.slow_test_files_by_pattern(adapter_class) }
20
-
21
- before do
22
- expect(KnapsackPro::Config::Env).to receive(:slow_test_file_pattern).at_least(1).and_return(slow_test_file_pattern)
23
- end
24
-
25
- context 'when slow_test_file_pattern is present' do
26
- let(:slow_test_file_pattern) { double }
27
- let(:test_file_entities) do
28
- [
29
- { 'path' => 'a_spec.rb' },
30
- { 'path' => 'b_spec.rb' },
31
- { 'path' => 'c_spec.rb' },
32
- ]
33
- end
34
- let(:slow_test_file_entities) do
35
- [
36
- { 'path' => 'b_spec.rb' },
37
- { 'path' => 'c_spec.rb' },
38
- { 'path' => 'd_spec.rb' },
39
- ]
40
- end
41
-
42
- it do
43
- test_file_pattern = double
44
- expect(KnapsackPro::TestFilePattern).to receive(:call).with(adapter_class).and_return(test_file_pattern)
45
- expect(described_class).to receive(:call).with(test_file_pattern).and_return(test_file_entities)
46
-
47
- expect(described_class).to receive(:call).with(slow_test_file_pattern, test_file_list_enabled: false).and_return(slow_test_file_entities)
48
-
49
- expect(subject).to eq([
50
- { 'path' => 'b_spec.rb' },
51
- { 'path' => 'c_spec.rb' },
52
- ])
53
- end
54
- end
55
-
56
- context 'when slow_test_file_pattern is not present' do
57
- let(:slow_test_file_pattern) { nil }
58
-
59
- it do
60
- expect { subject }.to raise_error RuntimeError, 'KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN is not defined'
61
- end
62
- end
63
- end
64
-
65
- describe '.select_test_files_that_can_be_run' do
66
- let(:adapter_class) { double }
67
- let(:test_file_entities_to_run) do
68
- [
69
- { 'path' => 'a_spec.rb' },
70
- { 'path' => 'b_spec.rb' },
71
- { 'path' => 'not_existing_on_disk_spec.rb' },
72
- ]
73
- end
74
- # test files existing on disk
75
- let(:test_file_entities) do
76
- [
77
- { 'path' => 'a_spec.rb' },
78
- { 'path' => 'b_spec.rb' },
79
- { 'path' => 'c_spec.rb' },
80
- ]
81
- end
82
-
83
- subject { described_class.select_test_files_that_can_be_run(adapter_class, test_file_entities_to_run) }
84
-
85
- it do
86
- test_file_pattern = double
87
- expect(KnapsackPro::TestFilePattern).to receive(:call).with(adapter_class).and_return(test_file_pattern)
88
- expect(described_class).to receive(:call).with(test_file_pattern).and_return(test_file_entities)
89
-
90
- expect(subject).to eq([
91
- { 'path' => 'a_spec.rb' },
92
- { 'path' => 'b_spec.rb' },
93
- ])
94
- end
95
- end
96
-
97
- describe '#call' do
98
- let(:test_file_list_enabled) { true }
99
- let(:test_file_pattern) { 'spec_fake/**{,/*/**}/*_spec.rb' }
100
-
101
- subject { described_class.new(test_file_pattern, test_file_list_enabled).call }
102
-
103
- context 'when KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN is not defined' do
104
- it do
105
- should eq([
106
- { 'path' => 'spec_fake/controllers/users_controller_spec.rb' },
107
- { 'path' => 'spec_fake/models/admin_spec.rb' },
108
- { 'path' => 'spec_fake/models/user_spec.rb' },
109
- ])
110
- end
111
- end
112
-
113
- context 'when KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN is defined' do
114
- let(:test_file_exclude_pattern) { 'spec_fake/controllers/*_spec.rb' }
115
-
116
- before do
117
- stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN' => test_file_exclude_pattern })
118
- end
119
-
120
- it do
121
- should eq([
122
- { 'path' => 'spec_fake/models/admin_spec.rb' },
123
- { 'path' => 'spec_fake/models/user_spec.rb' },
124
- ])
125
- end
126
- end
127
-
128
- context 'when KNAPSACK_PRO_TEST_FILE_LIST is defined' do
129
- # added spaces next to comma to check space is removed later
130
- let(:test_file_list) { 'spec/bar_spec.rb,spec/foo_spec.rb, spec/time_helpers_spec.rb:10 , spec/time_helpers_spec.rb:38' }
131
-
132
- before do
133
- stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_LIST' => test_file_list })
134
- end
135
-
136
- it do
137
- expect(subject).to eq([
138
- { 'path' => 'spec/bar_spec.rb' },
139
- { 'path' => 'spec/foo_spec.rb' },
140
- { 'path' => 'spec/time_helpers_spec.rb:10' },
141
- { 'path' => 'spec/time_helpers_spec.rb:38' },
142
- ])
143
- end
144
-
145
- context 'when test_file_list_enabled=false' do
146
- let(:test_file_list_enabled) { false }
147
-
148
- it do
149
- should eq([
150
- { 'path' => 'spec_fake/controllers/users_controller_spec.rb' },
151
- { 'path' => 'spec_fake/models/admin_spec.rb' },
152
- { 'path' => 'spec_fake/models/user_spec.rb' },
153
- ])
154
- end
155
- end
156
- end
157
-
158
- context 'when KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE is defined' do
159
- let(:test_file_list_source_file) { 'spec/fixtures/test_file_list_source_file.txt' }
160
-
161
- before do
162
- stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE' => test_file_list_source_file })
163
- end
164
-
165
- it do
166
- expect(subject).to eq([
167
- { 'path' => 'spec/test1_spec.rb' },
168
- { 'path' => 'spec/test2_spec.rb[1]' },
169
- { 'path' => 'spec/test3_spec.rb[1:2:3:4]' },
170
- { 'path' => 'spec/test4_spec.rb:4' },
171
- { 'path' => 'spec/test4_spec.rb:5' },
172
- ])
173
- end
174
- end
175
- end
176
- end
@@ -1,49 +0,0 @@
1
- describe KnapsackPro::TestFilePattern do
2
- describe '.call' do
3
- let(:adapter_class) { KnapsackPro::Adapters::BaseAdapter }
4
-
5
- subject { described_class.call(adapter_class) }
6
-
7
- before do
8
- expect(KnapsackPro::Config::Env).to receive(:test_file_pattern).and_return(env_test_file_pattern)
9
- end
10
-
11
- context 'when ENV defined' do
12
- let(:env_test_file_pattern) { 'spec/**{,/*/**}/*_spec.rb' }
13
-
14
- it { should eq env_test_file_pattern }
15
- end
16
-
17
- context 'when ENV not defined' do
18
- let(:env_test_file_pattern) { nil }
19
-
20
- it { should eq 'test/**{,/*/**}/*_test.rb' }
21
- end
22
- end
23
-
24
- describe '#test_dir' do
25
- let(:adapter_class) { KnapsackPro::Adapters::BaseAdapter }
26
-
27
- subject { described_class.test_dir(adapter_class) }
28
-
29
- before do
30
- expect(described_class).to receive(:call).with(adapter_class).and_return(test_file_pattern)
31
- end
32
-
33
- context 'when default test file pattern' do
34
- let(:test_file_pattern) { 'spec/**{,/*/**}/*_spec.rb' }
35
-
36
- it 'extracts test directory from the pattern' do
37
- expect(subject).to eq 'spec'
38
- end
39
- end
40
-
41
- context 'when test file pattern has multiple patterns' do
42
- let(:test_file_pattern) { '{spec/*_spec.rb,spec2/controllers/**/*_spec.rb}' }
43
-
44
- it 'extracts test directory from the first pattern' do
45
- expect(subject).to eq 'spec'
46
- end
47
- end
48
- end
49
- end
@@ -1,22 +0,0 @@
1
- describe KnapsackPro::TestFilePresenter do
2
- describe '.stringify_paths' do
3
- let(:test_file_paths) { ['a_spec.rb', 'b_spec.rb'] }
4
-
5
- subject { described_class.stringify_paths(test_file_paths) }
6
-
7
- it { should eq '"a_spec.rb" "b_spec.rb"' }
8
- end
9
-
10
- describe '.paths' do
11
- let(:test_files) do
12
- [
13
- { 'path' => 'a_spec.rb' },
14
- { 'path' => 'b_spec.rb' },
15
- ]
16
- end
17
-
18
- subject { described_class.paths(test_files) }
19
-
20
- it { should eq ['a_spec.rb', 'b_spec.rb'] }
21
- end
22
- end
@@ -1,41 +0,0 @@
1
- describe KnapsackPro::TestFilesWithTestCasesComposer do
2
- let(:test_files) do
3
- [
4
- { 'path' => 'spec/a_spec.rb' },
5
- { 'path' => 'spec/b_spec.rb' },
6
- { 'path' => 'spec/c_spec.rb' },
7
- { 'path' => 'spec/slow_1_spec.rb' },
8
- { 'path' => 'spec/slow_2_spec.rb' },
9
- ]
10
- end
11
- let(:slow_test_files) do
12
- [
13
- { 'path' => 'spec/slow_1_spec.rb', 'time_execution' => 1.0 },
14
- { 'path' => 'spec/slow_2_spec.rb', 'time_execution' => 2.0 },
15
- ]
16
- end
17
- let(:test_file_cases) do
18
- [
19
- { 'path' => 'spec/slow_1_spec.rb[1:1]' },
20
- { 'path' => 'spec/slow_1_spec.rb[1:2]' },
21
- { 'path' => 'spec/slow_2_spec.rb[1:1:1]' },
22
- { 'path' => 'spec/slow_2_spec.rb[1:1:2]' },
23
- { 'path' => 'spec/slow_2_spec.rb[1:1:3]' },
24
- ]
25
- end
26
-
27
- subject { described_class.call(test_files, slow_test_files, test_file_cases) }
28
-
29
- it 'returns test files that are not slow and test file cases for slow test files' do
30
- expect(subject).to eq([
31
- { 'path' => 'spec/a_spec.rb' },
32
- { 'path' => 'spec/b_spec.rb' },
33
- { 'path' => 'spec/c_spec.rb' },
34
- { 'path' => 'spec/slow_1_spec.rb[1:1]' },
35
- { 'path' => 'spec/slow_1_spec.rb[1:2]' },
36
- { 'path' => 'spec/slow_2_spec.rb[1:1:1]' },
37
- { 'path' => 'spec/slow_2_spec.rb[1:1:2]' },
38
- { 'path' => 'spec/slow_2_spec.rb[1:1:3]' },
39
- ])
40
- end
41
- end
@@ -1,60 +0,0 @@
1
- describe KnapsackPro::TestFlatDistributor do
2
- let(:test_flat_distributor) { described_class.new(test_files, node_total) }
3
- let(:node_total) { 2 }
4
- let(:test_files) do
5
- [
6
- { 'path' => 'spec/dir1/a_spec.rb' },
7
- { 'path' => 'spec/dir2/a_spec.rb' },
8
- { 'path' => 'spec/dir3/a_spec.rb' },
9
- { 'path' => 'spec/feature/e_spec.rb' },
10
- { 'path' => 'spec/models/b_spec.rb' },
11
- { 'path' => 'spec/feature/c_spec.rb' },
12
- { 'path' => 'spec/models/d_spec.rb' },
13
- { 'path' => 'spec/feature/a_spec.rb' },
14
- { 'path' => 'spec/models/f_spec.rb' },
15
- { 'path' => 'spec/models/g_spec.rb' },
16
- { 'path' => 'spec/dir4/h_spec.rb' },
17
- { 'path' => 'spec/models/i_spec.rb' },
18
- ]
19
- end
20
-
21
- describe '#nodes' do
22
- subject { test_flat_distributor.nodes }
23
-
24
- it do
25
- should eq({
26
- 0 => [
27
- { 'path' => 'spec/feature/a_spec.rb' },
28
- { 'path' => 'spec/feature/e_spec.rb' },
29
- { 'path' => 'spec/models/d_spec.rb' },
30
- { 'path' => 'spec/models/g_spec.rb' },
31
- { 'path' => 'spec/dir1/a_spec.rb' },
32
- { 'path' => 'spec/dir3/a_spec.rb' },
33
- ],
34
- 1 => [
35
- { 'path' => 'spec/feature/c_spec.rb' },
36
- { 'path' => 'spec/models/b_spec.rb' },
37
- { 'path' => 'spec/models/f_spec.rb' },
38
- { 'path' => 'spec/models/i_spec.rb' },
39
- { 'path' => 'spec/dir2/a_spec.rb' },
40
- { 'path' => 'spec/dir4/h_spec.rb' },
41
- ],
42
- })
43
- end
44
- end
45
-
46
- describe '#test_files_for_node' do
47
- subject { test_flat_distributor.test_files_for_node(1) }
48
-
49
- it do
50
- should eq([
51
- { 'path' => 'spec/feature/c_spec.rb' },
52
- { 'path' => 'spec/models/b_spec.rb' },
53
- { 'path' => 'spec/models/f_spec.rb' },
54
- { 'path' => 'spec/models/i_spec.rb' },
55
- { 'path' => 'spec/dir2/a_spec.rb' },
56
- { 'path' => 'spec/dir4/h_spec.rb' },
57
- ])
58
- end
59
- end
60
- end
@@ -1,184 +0,0 @@
1
- shared_examples 'default trakcer attributes' do
2
- it { expect(tracker.global_time).to eql 0 }
3
- it { expect(tracker.test_files_with_time).to eql({}) }
4
- it { expect(tracker.prerun_tests_loaded).to be false }
5
- end
6
-
7
- describe KnapsackPro::Tracker do
8
- let(:adapter) { 'RSpecAdapter' }
9
- let(:tracker) { described_class.send(:new) }
10
-
11
- before do
12
- allow(KnapsackPro::Config::Env).to receive(:test_runner_adapter).and_return(adapter)
13
- allow(KnapsackPro::Config::Env).to receive(:ci_node_index).and_return(0)
14
- end
15
-
16
- it_behaves_like 'default trakcer attributes'
17
-
18
- describe '#current_test_path' do
19
- subject { tracker.current_test_path }
20
-
21
- context 'when current_test_path not set' do
22
- it { should eql nil }
23
- end
24
-
25
- context 'when current_test_path set' do
26
- context 'when current_test_path has prefix ./' do
27
- before { tracker.current_test_path = './spec/models/user_spec.rb' }
28
- it { should eql 'spec/models/user_spec.rb' }
29
- end
30
-
31
- context 'when current_test_path has no prefix ./' do
32
- before { tracker.current_test_path = 'spec/models/user_spec.rb' }
33
- it { should eql 'spec/models/user_spec.rb' }
34
- end
35
- end
36
- end
37
-
38
- describe 'track time execution' do
39
- let(:test_paths) { ['a_spec.rb', 'b_spec.rb'] }
40
- let(:delta) { 0.02 }
41
-
42
- before do
43
- tracker.set_prerun_tests(test_paths)
44
- end
45
-
46
- shared_examples '#to_a' do
47
- subject { tracker.to_a }
48
-
49
- its(:size) { should eq 2 }
50
- it { expect(subject[0][:path]).to eq 'a_spec.rb' }
51
- it { expect(subject[0][:time_execution]).to be >= 0 }
52
- it { expect(subject[1][:path]).to eq 'b_spec.rb' }
53
- it { expect(subject[1][:time_execution]).to be >= 0 }
54
- end
55
-
56
- context 'without Timecop' do
57
- before do
58
- test_paths.each_with_index do |test_path, index|
59
- tracker.current_test_path = test_path
60
- tracker.start_timer
61
- sleep index.to_f / 10 + 0.1
62
- tracker.stop_timer
63
- end
64
- end
65
-
66
- it { expect(tracker.global_time).to be_within(delta).of(0.3) }
67
- it { expect(tracker.prerun_tests_loaded).to be true }
68
- it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
69
- it { expect(tracker.test_files_with_time['a_spec.rb'][:time_execution]).to be_within(delta).of(0.1) }
70
- it { expect(tracker.test_files_with_time['b_spec.rb'][:time_execution]).to be_within(delta).of(0.2) }
71
- it_behaves_like '#to_a'
72
- end
73
-
74
- context "with Timecop - Timecop shouldn't have impact on the measured test time" do
75
- let(:now) { Time.now }
76
-
77
- before do
78
- test_paths.each_with_index do |test_path, index|
79
- Timecop.freeze(now) do
80
- tracker.current_test_path = test_path
81
- tracker.start_timer
82
- end
83
-
84
- delay = index + 1
85
- Timecop.freeze(now+delay) do
86
- tracker.stop_timer
87
- end
88
- end
89
- end
90
-
91
- it { expect(tracker.global_time).to be > 0 }
92
- it { expect(tracker.global_time).to be_within(delta).of(0) }
93
- it { expect(tracker.prerun_tests_loaded).to be true }
94
- it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
95
- it { expect(tracker.test_files_with_time['a_spec.rb'][:time_execution]).to be_within(delta).of(0) }
96
- it { expect(tracker.test_files_with_time['b_spec.rb'][:time_execution]).to be_within(delta).of(0) }
97
- it_behaves_like '#to_a'
98
- end
99
-
100
- # https://github.com/KnapsackPro/knapsack_pro-ruby/issues/32
101
- context 'when start timer was not called (rspec-retry issue)' do
102
- before do
103
- test_paths.each_with_index do |test_path, index|
104
- tracker.current_test_path = test_path
105
- sleep 0.001
106
- tracker.stop_timer
107
- end
108
- end
109
-
110
- it { expect(tracker.global_time).to be > 0 }
111
- it { expect(tracker.prerun_tests_loaded).to be true }
112
- it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
113
- it { expect(tracker.test_files_with_time['a_spec.rb'][:time_execution]).to eq 0 }
114
- it '2nd spec (b_spec.rb) should have recorded time execution - because start_time was set during first call of stop_timer for the first spec (a_spec.rb)' do
115
- expect(tracker.test_files_with_time['b_spec.rb'][:time_execution]).to be > 0
116
- end
117
- it_behaves_like '#to_a'
118
- end
119
-
120
- context 'when a new tracker instance is created' do
121
- let(:non_pending_test_paths) { ['a_spec.rb', 'b_spec.rb'] }
122
- let(:test_paths) { non_pending_test_paths + ['pending_spec.rb'] }
123
-
124
- before do
125
- # measure tests only for non pending tests
126
- non_pending_test_paths.each_with_index do |test_path, index|
127
- tracker.current_test_path = test_path
128
- tracker.start_timer
129
- sleep index.to_f / 10 + 0.1
130
- tracker.stop_timer
131
- end
132
- end
133
-
134
- it '2nd tracker instance loads prerun tests from the disk' do
135
- expect(tracker.prerun_tests_loaded).to be true
136
- expect(tracker.to_a.size).to eq 3
137
- expect(tracker.to_a[0][:path]).to eq 'a_spec.rb'
138
- expect(tracker.to_a[0][:time_execution]).to be >= 0
139
- expect(tracker.to_a[1][:path]).to eq 'b_spec.rb'
140
- expect(tracker.to_a[1][:time_execution]).to be >= 0
141
- expect(tracker.to_a[2][:path]).to eq 'pending_spec.rb'
142
- expect(tracker.to_a[2][:time_execution]).to eq 0
143
-
144
- tracker2 = described_class.send(:new)
145
- expect(tracker2.prerun_tests_loaded).to be false
146
- expect(tracker2.to_a.size).to eq 3
147
- expect(tracker2.to_a[0][:path]).to eq 'a_spec.rb'
148
- expect(tracker2.to_a[0][:time_execution]).to be >= 0
149
- expect(tracker2.to_a[1][:path]).to eq 'b_spec.rb'
150
- expect(tracker2.to_a[1][:time_execution]).to be >= 0
151
- expect(tracker2.to_a[2][:path]).to eq 'pending_spec.rb'
152
- expect(tracker2.to_a[2][:time_execution]).to eq 0
153
- expect(tracker2.prerun_tests_loaded).to be true
154
- end
155
- end
156
- end
157
-
158
- describe '#reset!' do
159
- let(:test_file_path) { 'a_spec.rb' }
160
-
161
- before do
162
- tracker.set_prerun_tests([test_file_path])
163
- end
164
-
165
- before do
166
- expect(tracker.prerun_tests_loaded).to be true
167
-
168
- tracker.current_test_path = test_file_path
169
- tracker.start_timer
170
- sleep 0.1
171
- tracker.stop_timer
172
-
173
- expect(tracker.global_time).not_to eql 0
174
-
175
- tracker.reset!
176
- end
177
-
178
- it_behaves_like 'default trakcer attributes'
179
-
180
- it 'resets prerun_tests_loaded to false' do
181
- expect(tracker.prerun_tests_loaded).to be false
182
- end
183
- end
184
- end
@@ -1,55 +0,0 @@
1
- describe KnapsackPro::Utils do
2
- describe '.unsymbolize' do
3
- let(:test_files) do
4
- [
5
- { path: 'a_spec.rb', time_execution: 0.1 },
6
- { path: 'b_spec.rb', time_execution: 0.2 },
7
- ]
8
- end
9
-
10
- subject { described_class.unsymbolize(test_files) }
11
-
12
- it do
13
- should eq([
14
- { 'path' => 'a_spec.rb', 'time_execution' => 0.1 },
15
- { 'path' => 'b_spec.rb', 'time_execution' => 0.2 },
16
- ])
17
- end
18
- end
19
-
20
- describe '.time_now' do
21
- subject { described_class.time_now }
22
-
23
- context 'when Timecop does not mock the time' do
24
- it do
25
- now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
26
- expect(subject).to be_within(0.01).of(now)
27
- end
28
- end
29
-
30
- context 'when Timecop does mock the process clock' do
31
- around(:example) do |ex|
32
- unless Gem::Version.new(Timecop::VERSION) >= Gem::Version.new('0.9.9')
33
- raise 'Timecop >= 0.9.9 is required to run this test. Please run: bundle update'
34
- end
35
-
36
- if Gem::Version.new(Timecop::VERSION) >= Gem::Version.new('0.9.10')
37
- Timecop.mock_process_clock = true
38
- ex.run
39
- Timecop.mock_process_clock = false
40
- else
41
- ex.run
42
- end
43
- end
44
-
45
- it do
46
- now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
47
-
48
- time = Time.local(2020, 1, 31)
49
- Timecop.travel(time) do
50
- expect(subject).to be_within(0.01).of(now)
51
- end
52
- end
53
- end
54
- end
55
- end