knapsack_pro 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -3
  3. data/CHANGELOG.md +4 -0
  4. data/README.md +368 -4
  5. data/bin/knapsack_pro +20 -0
  6. data/circle.yml +2 -0
  7. data/knapsack_pro.gemspec +6 -1
  8. data/lib/knapsack_pro.rb +74 -0
  9. data/lib/knapsack_pro/adapters/base_adapter.rb +30 -0
  10. data/lib/knapsack_pro/adapters/cucumber_adapter.rb +40 -0
  11. data/lib/knapsack_pro/adapters/minitest_adapter.rb +52 -0
  12. data/lib/knapsack_pro/adapters/rspec_adapter.rb +48 -0
  13. data/lib/knapsack_pro/allocator.rb +40 -0
  14. data/lib/knapsack_pro/allocator_builder.rb +40 -0
  15. data/lib/knapsack_pro/client/api/action.rb +17 -0
  16. data/lib/knapsack_pro/client/api/v1/base.rb +15 -0
  17. data/lib/knapsack_pro/client/api/v1/build_distributions.rb +29 -0
  18. data/lib/knapsack_pro/client/api/v1/build_subsets.rb +29 -0
  19. data/lib/knapsack_pro/client/connection.rb +94 -0
  20. data/lib/knapsack_pro/config/ci/base.rb +22 -0
  21. data/lib/knapsack_pro/config/ci/buildkite.rb +27 -0
  22. data/lib/knapsack_pro/config/ci/circle.rb +29 -0
  23. data/lib/knapsack_pro/config/ci/semaphore.rb +28 -0
  24. data/lib/knapsack_pro/config/env.rb +111 -0
  25. data/lib/knapsack_pro/logger_wrapper.rb +15 -0
  26. data/lib/knapsack_pro/presenter.rb +25 -0
  27. data/lib/knapsack_pro/report.rb +20 -0
  28. data/lib/knapsack_pro/repository_adapter_initiator.rb +12 -0
  29. data/lib/knapsack_pro/repository_adapters/base_adapter.rb +14 -0
  30. data/lib/knapsack_pro/repository_adapters/env_adapter.rb +13 -0
  31. data/lib/knapsack_pro/repository_adapters/git_adapter.rb +19 -0
  32. data/lib/knapsack_pro/runners/base_runner.rb +31 -0
  33. data/lib/knapsack_pro/runners/cucumber_runner.rb +16 -0
  34. data/lib/knapsack_pro/runners/minitest_runner.rb +26 -0
  35. data/lib/knapsack_pro/runners/rspec_runner.rb +16 -0
  36. data/lib/knapsack_pro/task_loader.rb +11 -0
  37. data/lib/knapsack_pro/test_file_cleaner.rb +7 -0
  38. data/lib/knapsack_pro/test_file_finder.rb +33 -0
  39. data/lib/knapsack_pro/test_file_pattern.rb +7 -0
  40. data/lib/knapsack_pro/test_file_presenter.rb +11 -0
  41. data/lib/knapsack_pro/test_flat_distributor.rb +84 -0
  42. data/lib/knapsack_pro/tracker.rb +64 -0
  43. data/lib/knapsack_pro/version.rb +1 -1
  44. data/lib/tasks/cucumber.rake +7 -0
  45. data/lib/tasks/minitest.rake +7 -0
  46. data/lib/tasks/rspec.rake +7 -0
  47. data/spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/invalid_test_suite_token.yml +50 -0
  48. data/spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/success.yml +52 -0
  49. data/spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/invalid_test_suite_token.yml +50 -0
  50. data/spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/success.yml +50 -0
  51. data/spec/integration/api/build_distributions_subset_spec.rb +74 -0
  52. data/spec/integration/api/build_subsets_create_spec.rb +76 -0
  53. data/spec/knapsack_pro/adapters/base_adapter_spec.rb +63 -0
  54. data/spec/knapsack_pro/adapters/cucumber_adapter_spec.rb +71 -0
  55. data/spec/knapsack_pro/adapters/minitest_adapter_spec.rb +107 -0
  56. data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +94 -0
  57. data/spec/knapsack_pro/allocator_builder_spec.rb +45 -0
  58. data/spec/knapsack_pro/allocator_spec.rb +80 -0
  59. data/spec/knapsack_pro/client/api/action_spec.rb +17 -0
  60. data/spec/knapsack_pro/client/api/v1/base_spec.rb +2 -0
  61. data/spec/knapsack_pro/client/api/v1/build_distributions_spec.rb +35 -0
  62. data/spec/knapsack_pro/client/api/v1/build_subsets_spec.rb +35 -0
  63. data/spec/knapsack_pro/client/connection_spec.rb +138 -0
  64. data/spec/knapsack_pro/config/ci/base_spec.rb +7 -0
  65. data/spec/knapsack_pro/config/ci/buildkite_spec.rb +74 -0
  66. data/spec/knapsack_pro/config/ci/circle_spec.rb +74 -0
  67. data/spec/knapsack_pro/config/ci/semaphore_spec.rb +74 -0
  68. data/spec/knapsack_pro/config/env_spec.rb +368 -0
  69. data/spec/knapsack_pro/logger_wrapper_spec.rb +15 -0
  70. data/spec/knapsack_pro/presenter_spec.rb +57 -0
  71. data/spec/knapsack_pro/report_spec.rb +68 -0
  72. data/spec/knapsack_pro/repository_adapter_initiator_spec.rb +21 -0
  73. data/spec/knapsack_pro/repository_adapters/base_adapter_spec.rb +13 -0
  74. data/spec/knapsack_pro/repository_adapters/env_adapter_spec.rb +27 -0
  75. data/spec/knapsack_pro/repository_adapters/git_adapter_spec.rb +27 -0
  76. data/spec/knapsack_pro/runners/base_runner_spec.rb +61 -0
  77. data/spec/knapsack_pro/runners/cucumber_runner_spec.rb +47 -0
  78. data/spec/knapsack_pro/runners/minitest_runner_spec.rb +34 -0
  79. data/spec/knapsack_pro/runners/rspec_runner_spec.rb +49 -0
  80. data/spec/knapsack_pro/task_loader_spec.rb +14 -0
  81. data/spec/knapsack_pro/test_file_cleaner_spec.rb +11 -0
  82. data/spec/knapsack_pro/test_file_finder_spec.rb +35 -0
  83. data/spec/knapsack_pro/test_file_pattern_spec.rb +23 -0
  84. data/spec/knapsack_pro/test_file_presenter_spec.rb +22 -0
  85. data/spec/knapsack_pro/test_flat_distributor_spec.rb +60 -0
  86. data/spec/knapsack_pro/tracker_spec.rb +102 -0
  87. data/spec/knapsack_pro_spec.rb +56 -0
  88. data/spec/spec_helper.rb +11 -1
  89. data/spec/support/fakes/cucumber.rb +12 -0
  90. data/spec/support/fakes/minitest.rb +12 -0
  91. data/spec/support/shared_examples/adapter.rb +17 -0
  92. data/spec_fake/controllers/users_controller_spec.rb +0 -0
  93. data/spec_fake/models/admin_spec.rb +0 -0
  94. data/spec_fake/models/user_spec.rb +0 -0
  95. data/spec_fake/spec_helper.rb +0 -0
  96. data/test_fake/a_test.rb +0 -0
  97. data/test_fake/b_test.rb +0 -0
  98. metadata +212 -12
  99. data/Gemfile.lock +0 -69
  100. data/spec/knapsack_spec.rb +0 -3
@@ -0,0 +1,7 @@
1
+ describe KnapsackPro::Config::CI::Base do
2
+ its(:node_total) { should be nil }
3
+ its(:node_index) { should be nil }
4
+ its(:commit_hash) { should be nil }
5
+ its(:branch) { should be nil }
6
+ its(:project_dir) { should be nil }
7
+ end
@@ -0,0 +1,74 @@
1
+ describe KnapsackPro::Config::CI::Buildkite do
2
+ let(:env) { {} }
3
+
4
+ before do
5
+ stub_const('ENV', env)
6
+ end
7
+
8
+ it { should be_kind_of KnapsackPro::Config::CI::Base }
9
+
10
+ describe '#node_total' do
11
+ subject { described_class.new.node_total }
12
+
13
+ context 'when environment exists' do
14
+ let(:env) { { 'BUILDKITE_PARALLEL_JOB_COUNT' => 4 } }
15
+ it { should eql 4 }
16
+ end
17
+
18
+ context "when environment doesn't exist" do
19
+ it { should be nil }
20
+ end
21
+ end
22
+
23
+ describe '#node_index' do
24
+ subject { described_class.new.node_index }
25
+
26
+ context 'when environment exists' do
27
+ let(:env) { { 'BUILDKITE_PARALLEL_JOB' => 3 } }
28
+ it { should eql 3 }
29
+ end
30
+
31
+ context "when environment doesn't exist" do
32
+ it { should be nil }
33
+ end
34
+ end
35
+
36
+ describe '#commit_hash' do
37
+ subject { described_class.new.commit_hash }
38
+
39
+ context 'when environment exists' do
40
+ let(:env) { { 'BUILDKITE_COMMIT' => '3fa64859337f6e56409d49f865d13fd7' } }
41
+ it { should eql '3fa64859337f6e56409d49f865d13fd7' }
42
+ end
43
+
44
+ context "when environment doesn't exist" do
45
+ it { should be nil }
46
+ end
47
+ end
48
+
49
+ describe '#branch' do
50
+ subject { described_class.new.branch }
51
+
52
+ context 'when environment exists' do
53
+ let(:env) { { 'BUILDKITE_BRANCH' => 'master' } }
54
+ it { should eql 'master' }
55
+ end
56
+
57
+ context "when environment doesn't exist" do
58
+ it { should be nil }
59
+ end
60
+ end
61
+
62
+ describe '#project_dir' do
63
+ subject { described_class.new.project_dir }
64
+
65
+ context 'when environment exists' do
66
+ let(:env) { { 'BUILDKITE_BUILD_CHECKOUT_PATH' => '/home/user/knapsack_pro-ruby' } }
67
+ it { should eql '/home/user/knapsack_pro-ruby' }
68
+ end
69
+
70
+ context "when environment doesn't exist" do
71
+ it { should be nil }
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,74 @@
1
+ describe KnapsackPro::Config::CI::Circle do
2
+ let(:env) { {} }
3
+
4
+ before do
5
+ stub_const('ENV', env)
6
+ end
7
+
8
+ it { should be_kind_of KnapsackPro::Config::CI::Base }
9
+
10
+ describe '#node_total' do
11
+ subject { described_class.new.node_total }
12
+
13
+ context 'when environment exists' do
14
+ let(:env) { { 'CIRCLE_NODE_TOTAL' => 4 } }
15
+ it { should eql 4 }
16
+ end
17
+
18
+ context "when environment doesn't exist" do
19
+ it { should be nil }
20
+ end
21
+ end
22
+
23
+ describe '#node_index' do
24
+ subject { described_class.new.node_index }
25
+
26
+ context 'when environment exists' do
27
+ let(:env) { { 'CIRCLE_NODE_INDEX' => 3 } }
28
+ it { should eql 3 }
29
+ end
30
+
31
+ context "when environment doesn't exist" do
32
+ it { should be nil }
33
+ end
34
+ end
35
+
36
+ describe '#commit_hash' do
37
+ subject { described_class.new.commit_hash }
38
+
39
+ context 'when environment exists' do
40
+ let(:env) { { 'CIRCLE_SHA1' => '3fa64859337f6e56409d49f865d13fd7' } }
41
+ it { should eql '3fa64859337f6e56409d49f865d13fd7' }
42
+ end
43
+
44
+ context "when environment doesn't exist" do
45
+ it { should be nil }
46
+ end
47
+ end
48
+
49
+ describe '#branch' do
50
+ subject { described_class.new.branch }
51
+
52
+ context 'when environment exists' do
53
+ let(:env) { { 'CIRCLE_BRANCH' => 'master' } }
54
+ it { should eql 'master' }
55
+ end
56
+
57
+ context "when environment doesn't exist" do
58
+ it { should be nil }
59
+ end
60
+ end
61
+
62
+ describe '#project_dir' do
63
+ subject { described_class.new.project_dir }
64
+
65
+ context 'when environment exists' do
66
+ let(:env) { { 'CIRCLE_PROJECT_REPONAME' => 'knapsack_pro-ruby' } }
67
+ it { should eql '/home/ubuntu/knapsack_pro-ruby' }
68
+ end
69
+
70
+ context "when environment doesn't exist" do
71
+ it { should be nil }
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,74 @@
1
+ describe KnapsackPro::Config::CI::Semaphore do
2
+ let(:env) { {} }
3
+
4
+ before do
5
+ stub_const('ENV', env)
6
+ end
7
+
8
+ it { should be_kind_of KnapsackPro::Config::CI::Base }
9
+
10
+ describe '#node_total' do
11
+ subject { described_class.new.node_total }
12
+
13
+ context 'when environment exists' do
14
+ let(:env) { { 'SEMAPHORE_THREAD_COUNT' => 4 } }
15
+ it { should eql 4 }
16
+ end
17
+
18
+ context "when environment doesn't exist" do
19
+ it { should be nil }
20
+ end
21
+ end
22
+
23
+ describe '#node_index' do
24
+ subject { described_class.new.node_index }
25
+
26
+ context 'when environment exists' do
27
+ let(:env) { { 'SEMAPHORE_CURRENT_THREAD' => 4 } }
28
+ it { should eql 3 }
29
+ end
30
+
31
+ context "when environment doesn't exist" do
32
+ it { should be nil }
33
+ end
34
+ end
35
+
36
+ describe '#commit_hash' do
37
+ subject { described_class.new.commit_hash }
38
+
39
+ context 'when environment exists' do
40
+ let(:env) { { 'REVISION' => '3fa64859337f6e56409d49f865d13fd7' } }
41
+ it { should eql '3fa64859337f6e56409d49f865d13fd7' }
42
+ end
43
+
44
+ context "when environment doesn't exist" do
45
+ it { should be nil }
46
+ end
47
+ end
48
+
49
+ describe '#branch' do
50
+ subject { described_class.new.branch }
51
+
52
+ context 'when environment exists' do
53
+ let(:env) { { 'BRANCH_NAME' => 'master' } }
54
+ it { should eql 'master' }
55
+ end
56
+
57
+ context "when environment doesn't exist" do
58
+ it { should be nil }
59
+ end
60
+ end
61
+
62
+ describe '#project_dir' do
63
+ subject { described_class.new.project_dir }
64
+
65
+ context 'when environment exists' do
66
+ let(:env) { { 'SEMAPHORE_PROJECT_DIR' => '/home/runner/knapsack_pro-ruby' } }
67
+ it { should eql '/home/runner/knapsack_pro-ruby' }
68
+ end
69
+
70
+ context "when environment doesn't exist" do
71
+ it { should be nil }
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,368 @@
1
+ describe KnapsackPro::Config::Env do
2
+ before { stub_const("ENV", {}) }
3
+
4
+ describe '.ci_node_total' do
5
+ subject { described_class.ci_node_total }
6
+
7
+ context 'when ENV exists' do
8
+ context 'when KNAPSACK_PRO_CI_NODE_TOTAL has value' do
9
+ before { stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_TOTAL' => '5' }) }
10
+ it { should eq 5 }
11
+ end
12
+
13
+ context 'when CI environment has value' do
14
+ before do
15
+ expect(described_class).to receive(:ci_env_for).with(:node_total).and_return(4)
16
+ end
17
+
18
+ it { should eq 4 }
19
+ end
20
+ end
21
+
22
+ context "when ENV doesn't exist" do
23
+ it { should eq 1 }
24
+ end
25
+ end
26
+
27
+ describe '.ci_node_index' do
28
+ subject { described_class.ci_node_index }
29
+
30
+ context 'when ENV exists' do
31
+ context 'when KNAPSACK_PRO_CI_NODE_INDEX has value' do
32
+ before { stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_INDEX' => '3' }) }
33
+ it { should eq 3 }
34
+ end
35
+
36
+ context 'when CI environment has value' do
37
+ before do
38
+ expect(described_class).to receive(:ci_env_for).with(:node_index).and_return(2)
39
+ end
40
+
41
+ it { should eq 2 }
42
+ end
43
+ end
44
+
45
+ context "when ENV doesn't exist" do
46
+ it { should eq 0 }
47
+ end
48
+ end
49
+
50
+ describe '.commit_hash' do
51
+ subject { described_class.commit_hash }
52
+
53
+ context 'when ENV exists' do
54
+ context 'when KNAPSACK_PRO_COMMIT_HASH has value' do
55
+ before { stub_const("ENV", { 'KNAPSACK_PRO_COMMIT_HASH' => '3fa64859337f6e56409d49f865d13fd7' }) }
56
+ it { should eq '3fa64859337f6e56409d49f865d13fd7' }
57
+ end
58
+
59
+ context 'when CI environment has value' do
60
+ before do
61
+ expect(described_class).to receive(:ci_env_for).with(:commit_hash).and_return('fe61a08118d0d52e97c38666eba1eaf3')
62
+ end
63
+
64
+ it { should eq 'fe61a08118d0d52e97c38666eba1eaf3' }
65
+ end
66
+ end
67
+
68
+ context "when ENV doesn't exist" do
69
+ it { should be nil }
70
+ end
71
+ end
72
+
73
+ describe '.branch' do
74
+ subject { described_class.branch }
75
+
76
+ context 'when ENV exists' do
77
+ context 'when KNAPSACK_PRO_BRANCH has value' do
78
+ before { stub_const("ENV", { 'KNAPSACK_PRO_BRANCH' => 'master' }) }
79
+ it { should eq 'master' }
80
+ end
81
+
82
+ context 'when CI environment has value' do
83
+ before do
84
+ expect(described_class).to receive(:ci_env_for).with(:branch).and_return('feature-branch')
85
+ end
86
+
87
+ it { should eq 'feature-branch' }
88
+ end
89
+ end
90
+
91
+ context "when ENV doesn't exist" do
92
+ it { should be nil }
93
+ end
94
+ end
95
+
96
+ describe '.project_dir' do
97
+ subject { described_class.project_dir }
98
+
99
+ context 'when ENV exists' do
100
+ context 'when KNAPSACK_PRO_PROJECT_DIR has value' do
101
+ before { stub_const("ENV", { 'KNAPSACK_PRO_PROJECT_DIR' => '/home/user/myapp' }) }
102
+ it { should eq '/home/user/myapp' }
103
+ end
104
+
105
+ context 'when CI environment has value' do
106
+ before do
107
+ expect(described_class).to receive(:ci_env_for).with(:project_dir).and_return('/home/runner/myapp')
108
+ end
109
+
110
+ it { should eq '/home/runner/myapp' }
111
+ end
112
+ end
113
+
114
+ context "when ENV doesn't exist" do
115
+ it { should be nil }
116
+ end
117
+ end
118
+
119
+ describe '.test_file_pattern' do
120
+ subject { described_class.test_file_pattern }
121
+
122
+ context 'when ENV exists' do
123
+ let(:test_file_pattern) { 'custom_spec/**/*_spec.rb' }
124
+ before { stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_PATTERN' => test_file_pattern }) }
125
+ it { should eq test_file_pattern }
126
+ end
127
+
128
+ context "when ENV doesn't exist" do
129
+ it { should be_nil }
130
+ end
131
+ end
132
+
133
+ describe '.repository_adapter' do
134
+ subject { described_class.repository_adapter }
135
+
136
+ context 'when ENV exists' do
137
+ let(:repository_adapter) { 'git' }
138
+ before { stub_const("ENV", { 'KNAPSACK_PRO_REPOSITORY_ADAPTER' => repository_adapter }) }
139
+ it { should eq repository_adapter }
140
+ end
141
+
142
+ context "when ENV doesn't exist" do
143
+ it { should be_nil }
144
+ end
145
+ end
146
+
147
+ describe '.recording_enabled' do
148
+ subject { described_class.recording_enabled }
149
+
150
+ context 'when ENV exists' do
151
+ let(:recording_enabled) { 'true' }
152
+ before { stub_const("ENV", { 'KNAPSACK_PRO_RECORDING_ENABLED' => recording_enabled }) }
153
+ it { should eq recording_enabled }
154
+ end
155
+
156
+ context "when ENV doesn't exist" do
157
+ it { should be_nil }
158
+ end
159
+ end
160
+
161
+ describe '.recording_enabled?' do
162
+ subject { described_class.recording_enabled? }
163
+
164
+ before do
165
+ expect(described_class).to receive(:recording_enabled).and_return(recording_enabled)
166
+ end
167
+
168
+ context 'when enabled' do
169
+ let(:recording_enabled) { 'true' }
170
+
171
+ it { should be true }
172
+ end
173
+
174
+ context 'when disabled' do
175
+ let(:recording_enabled) { nil }
176
+
177
+ it { should be false }
178
+ end
179
+ end
180
+
181
+ describe '.endpoint' do
182
+ subject { described_class.endpoint }
183
+
184
+ context 'when ENV exists' do
185
+ let(:endpoint) { 'http://api-custom-url.knapsackpro.com' }
186
+ before { stub_const("ENV", { 'KNAPSACK_PRO_ENDPOINT' => endpoint }) }
187
+ it { should eq endpoint }
188
+ end
189
+
190
+ context "when ENV doesn't exist" do
191
+ context 'when default mode' do
192
+ it { should eq 'http://api.knapsackpro.com' }
193
+ end
194
+
195
+ context 'when development mode' do
196
+ before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'development' }) }
197
+ it { should eq 'http://api.knapsackpro.dev:3000' }
198
+ end
199
+
200
+ context 'when test mode' do
201
+ before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'test' }) }
202
+ it { should eq 'http://api-staging.knapsackpro.com' }
203
+ end
204
+
205
+ context 'when production mode' do
206
+ before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'production' }) }
207
+ it { should eq 'http://api.knapsackpro.com' }
208
+ end
209
+
210
+ context 'when unknown mode' do
211
+ before do
212
+ expect(described_class).to receive(:mode).and_return(:fake)
213
+ end
214
+
215
+ it do
216
+ expect { subject }.to raise_error('Missing environment variable KNAPSACK_PRO_ENDPOINT')
217
+ end
218
+ end
219
+ end
220
+ end
221
+
222
+ describe '.test_suite_token' do
223
+ subject { described_class.test_suite_token }
224
+
225
+ context 'when ENV exists' do
226
+ let(:token) { 'xyz' }
227
+ before { stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN' => 'xyz' }) }
228
+ it { should eq token }
229
+ end
230
+
231
+ context "when ENV doesn't exist" do
232
+ it do
233
+ expect { subject }.to raise_error('Missing environment variable KNAPSACK_PRO_TEST_SUITE_TOKEN')
234
+ end
235
+ end
236
+ end
237
+
238
+ describe '.test_suite_token_rspec' do
239
+ subject { described_class.test_suite_token_rspec }
240
+
241
+ context 'when ENV exists' do
242
+ let(:test_suite_token_rspec) { 'rspec-token' }
243
+ before { stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC' => test_suite_token_rspec }) }
244
+ it { should eq test_suite_token_rspec }
245
+ end
246
+
247
+ context "when ENV doesn't exist" do
248
+ it { should be_nil }
249
+ end
250
+ end
251
+
252
+ describe '.test_suite_token_minitest' do
253
+ subject { described_class.test_suite_token_minitest }
254
+
255
+ context 'when ENV exists' do
256
+ let(:test_suite_token_minitest) { 'minitest-token' }
257
+ before { stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST' => test_suite_token_minitest }) }
258
+ it { should eq test_suite_token_minitest }
259
+ end
260
+
261
+ context "when ENV doesn't exist" do
262
+ it { should be_nil }
263
+ end
264
+ end
265
+
266
+ describe '.test_suite_token_cucumber' do
267
+ subject { described_class.test_suite_token_cucumber }
268
+
269
+ context 'when ENV exists' do
270
+ let(:test_suite_token_cucumber) { 'cucumber-token' }
271
+ before { stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER' => test_suite_token_cucumber }) }
272
+ it { should eq test_suite_token_cucumber }
273
+ end
274
+
275
+ context "when ENV doesn't exist" do
276
+ it { should be_nil }
277
+ end
278
+ end
279
+
280
+ describe '.mode' do
281
+ subject { described_class.mode }
282
+
283
+ context 'when ENV exists' do
284
+ context 'when development mode' do
285
+ before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'development' }) }
286
+
287
+ it { should eq :development }
288
+ end
289
+
290
+ context 'when test mode' do
291
+ before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'test' }) }
292
+
293
+ it { should eq :test }
294
+ end
295
+
296
+ context 'when production mode' do
297
+ before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'production' }) }
298
+
299
+ it { should eq :production }
300
+ end
301
+
302
+ context 'when fake mode' do
303
+ before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'fake' }) }
304
+
305
+ it do
306
+ expect { subject }.to raise_error(ArgumentError)
307
+ end
308
+ end
309
+
310
+ context 'when blank mode' do
311
+ before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => '' }) }
312
+
313
+ it do
314
+ expect { subject }.to raise_error(ArgumentError)
315
+ end
316
+ end
317
+ end
318
+
319
+ context "when ENV doesn't exist" do
320
+ it { should eq :production }
321
+ end
322
+ end
323
+
324
+ describe '.ci_env_for' do
325
+ let(:env_name) { :node_total }
326
+
327
+ subject { described_class.ci_env_for(env_name) }
328
+
329
+ context 'when CI has no value for env_name method' do
330
+ before do
331
+ expect(KnapsackPro::Config::CI::Circle).to receive_message_chain(:new, env_name).and_return(nil)
332
+ expect(KnapsackPro::Config::CI::Semaphore).to receive_message_chain(:new, env_name).and_return(nil)
333
+ expect(KnapsackPro::Config::CI::Buildkite).to receive_message_chain(:new, env_name).and_return(nil)
334
+ end
335
+
336
+ it do
337
+ expect(subject).to be_nil
338
+ end
339
+ end
340
+
341
+ context 'when CI has value for env_name method' do
342
+ let(:circle_env) { double(:circle) }
343
+ let(:semaphore_env) { double(:semaphore) }
344
+ let(:buildkite_env) { double(:buildkite) }
345
+
346
+ before do
347
+ allow(KnapsackPro::Config::CI::Circle).to receive_message_chain(:new, env_name).and_return(circle_env)
348
+ allow(KnapsackPro::Config::CI::Semaphore).to receive_message_chain(:new, env_name).and_return(semaphore_env)
349
+ allow(KnapsackPro::Config::CI::Buildkite).to receive_message_chain(:new, env_name).and_return(buildkite_env)
350
+ end
351
+
352
+ it { should eq circle_env }
353
+
354
+ context do
355
+ let(:circle_env) { nil }
356
+
357
+ it { should eq semaphore_env }
358
+ end
359
+
360
+ context do
361
+ let(:circle_env) { nil }
362
+ let(:semaphore_env) { nil }
363
+
364
+ it { should eq buildkite_env }
365
+ end
366
+ end
367
+ end
368
+ end