coveralls_reborn 0.26.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,435 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Coveralls::Configuration do
6
- before do
7
- allow(ENV).to receive(:[]).and_return(nil)
8
- end
9
-
10
- describe '.configuration' do
11
- it 'returns a hash with the default keys' do
12
- config = described_class.configuration
13
- expect(config).to be_a(Hash)
14
- expect(config.keys).to include(:environment)
15
- expect(config.keys).to include(:git)
16
- end
17
-
18
- context 'with yaml_config' do
19
- let(:repo_token) { SecureRandom.hex(4) }
20
- let(:repo_secret_token) { SecureRandom.hex(4) }
21
- let(:yaml_config) do
22
- {
23
- 'repo_token' => repo_token,
24
- 'repo_secret_token' => repo_secret_token
25
- }
26
- end
27
-
28
- before do
29
- allow(File).to receive(:exist?).with(described_class.configuration_path).and_return(true)
30
- allow(YAML).to receive(:load_file).with(described_class.configuration_path).and_return(yaml_config)
31
- end
32
-
33
- it 'sets the Yaml config and associated variables if present' do
34
- config = described_class.configuration
35
- expect(config[:configuration]).to eq(yaml_config)
36
- expect(config[:repo_token]).to eq(repo_token)
37
- end
38
-
39
- it 'uses the repo_secret_token if the repo_token is not set' do
40
- yaml_config.delete('repo_token')
41
- config = described_class.configuration
42
- expect(config[:configuration]).to eq(yaml_config)
43
- expect(config[:repo_token]).to eq(repo_secret_token)
44
- end
45
- end
46
-
47
- context 'when repo_token is in environment' do
48
- let(:repo_token) { SecureRandom.hex(4) }
49
-
50
- before do
51
- allow(ENV).to receive(:[]).with('COVERALLS_REPO_TOKEN').and_return(repo_token)
52
- end
53
-
54
- it 'pulls the repo token from the environment if set' do
55
- config = described_class.configuration
56
- expect(config[:repo_token]).to eq(repo_token)
57
- end
58
- end
59
-
60
- context 'when parallel is in environment' do
61
- before do
62
- allow(ENV).to receive(:[]).with('COVERALLS_PARALLEL').and_return(true)
63
- end
64
-
65
- it 'sets parallel to true if present' do
66
- config = described_class.configuration
67
- expect(config[:parallel]).to be true
68
- end
69
- end
70
-
71
- context 'when flag_name is in environment' do
72
- before do
73
- allow(ENV).to receive(:[]).with('COVERALLS_FLAG_NAME').and_return(true)
74
- end
75
-
76
- it 'sets flag_name to true if present' do
77
- config = described_class.configuration
78
- expect(config[:flag_name]).to be true
79
- end
80
- end
81
-
82
- context 'with services' do
83
- def services
84
- {
85
- appveyor: 'APPVEYOR',
86
- circleci: 'CIRCLECI',
87
- gitlab: 'GITLAB_CI',
88
- jenkins: 'JENKINS_URL',
89
- semaphore: 'SEMAPHORE',
90
- tddium: 'TDDIUM',
91
- travis: 'TRAVIS',
92
- coveralls_local: 'COVERALLS_RUN_LOCALLY',
93
- generic: 'CI_NAME'
94
- }
95
- end
96
-
97
- shared_examples 'a service' do |service_name|
98
- let(:service_variable) { options[:service_variable] }
99
-
100
- before do
101
- allow(ENV).to receive(:[]).with(services[service_name]).and_return('1')
102
- described_class.configuration
103
- end
104
-
105
- it 'sets service parameters for this service and no other' do
106
- services.each_key.reject { |service| service == service_name }.each do |service|
107
- expect(described_class).not_to have_received(:"define_service_params_for_#{service}")
108
- end
109
-
110
- expect(described_class).to have_received(:"define_service_params_for_#{service_name}") unless service_name == :generic
111
- expect(described_class).to have_received(:define_standard_service_params_for_generic_ci)
112
- end
113
- end
114
-
115
- before do
116
- services.each_key do |service|
117
- allow(described_class).to receive(:"define_service_params_for_#{service}")
118
- end
119
-
120
- allow(described_class).to receive(:define_standard_service_params_for_generic_ci)
121
- end
122
-
123
- context 'with env based service name' do
124
- let(:service_name) { 'travis-enterprise' }
125
-
126
- before do
127
- allow(ENV).to receive(:[]).with('TRAVIS').and_return('1')
128
- allow(ENV).to receive(:[]).with('COVERALLS_SERVICE_NAME').and_return(service_name)
129
- end
130
-
131
- it 'pulls the service name from the environment if set' do
132
- config = described_class.configuration
133
- expect(config[:service_name]).to eq(service_name)
134
- end
135
- end
136
-
137
- context 'when using AppVeyor' do
138
- it_behaves_like 'a service', :appveyor
139
- end
140
-
141
- context 'when using CircleCI' do
142
- it_behaves_like 'a service', :circleci
143
- end
144
-
145
- context 'when using GitLab CI' do
146
- it_behaves_like 'a service', :gitlab
147
- end
148
-
149
- context 'when using Jenkins' do
150
- it_behaves_like 'a service', :jenkins
151
- end
152
-
153
- context 'when using Semaphore' do
154
- it_behaves_like 'a service', :semaphore
155
- end
156
-
157
- context 'when using Tddium' do
158
- it_behaves_like 'a service', :tddium
159
- end
160
-
161
- context 'when using Travis' do
162
- it_behaves_like 'a service', :travis
163
- end
164
-
165
- context 'when running Coveralls locally' do
166
- it_behaves_like 'a service', :coveralls_local
167
- end
168
-
169
- context 'when using a generic CI' do
170
- it_behaves_like 'a service', :generic
171
- end
172
- end
173
- end
174
-
175
- describe '.define_service_params_for_travis' do
176
- let(:travis_job_id) { SecureRandom.hex(4) }
177
-
178
- before do
179
- allow(ENV).to receive(:[]).with('TRAVIS_JOB_ID').and_return(travis_job_id)
180
- end
181
-
182
- it 'sets the service_job_id' do
183
- config = {}
184
- described_class.define_service_params_for_travis(config, nil)
185
- expect(config[:service_job_id]).to eq(travis_job_id)
186
- end
187
-
188
- it 'sets the service_name to travis-ci by default' do
189
- config = {}
190
- described_class.define_service_params_for_travis(config, nil)
191
- expect(config[:service_name]).to eq('travis-ci')
192
- end
193
-
194
- it 'sets the service_name to a value if one is passed in' do
195
- config = {}
196
- random_name = SecureRandom.hex(4)
197
- described_class.define_service_params_for_travis(config, random_name)
198
- expect(config[:service_name]).to eq(random_name)
199
- end
200
- end
201
-
202
- describe '.define_service_params_for_circleci' do
203
- let(:circle_workflow_id) { 1234 }
204
- let(:ci_pull_request) { 'repo/pull/12' }
205
- let(:circle_build_num) { SecureRandom.hex(4) }
206
- let(:circle_sha1) { SecureRandom.hex(32) }
207
- let(:circle_branch) { SecureRandom.hex(4) }
208
-
209
- before do
210
- allow(ENV).to receive(:[]).with('CIRCLE_WORKFLOW_ID').and_return(circle_workflow_id)
211
- allow(ENV).to receive(:[]).with('CI_PULL_REQUEST').and_return(ci_pull_request)
212
- allow(ENV).to receive(:[]).with('CIRCLE_BUILD_NUM').and_return(circle_build_num)
213
- allow(ENV).to receive(:[]).with('CIRCLE_SHA1').and_return(circle_sha1)
214
- allow(ENV).to receive(:[]).with('CIRCLE_BRANCH').and_return(circle_branch)
215
- end
216
-
217
- it 'sets the expected parameters' do
218
- config = {}
219
- described_class.define_service_params_for_circleci(config)
220
- expect(config).to include(
221
- service_name: 'circleci',
222
- service_number: circle_workflow_id,
223
- service_pull_request: '12',
224
- service_job_number: circle_build_num,
225
- git_commit: circle_sha1,
226
- git_branch: circle_branch
227
- )
228
- end
229
- end
230
-
231
- describe '.define_service_params_for_gitlab' do
232
- let(:commit_sha) { SecureRandom.hex(32) }
233
- let(:service_job_number) { 'spec:one' }
234
- let(:service_job_id) { 1234 }
235
- let(:service_branch) { 'feature' }
236
- let(:service_number) { 5678 }
237
-
238
- before do
239
- allow(ENV).to receive(:[]).with('CI_BUILD_NAME').and_return(service_job_number)
240
- allow(ENV).to receive(:[]).with('CI_PIPELINE_ID').and_return(service_number)
241
- allow(ENV).to receive(:[]).with('CI_BUILD_ID').and_return(service_job_id)
242
- allow(ENV).to receive(:[]).with('CI_BUILD_REF_NAME').and_return(service_branch)
243
- allow(ENV).to receive(:[]).with('CI_BUILD_REF').and_return(commit_sha)
244
- end
245
-
246
- it 'sets the expected parameters' do
247
- config = {}
248
- described_class.define_service_params_for_gitlab(config)
249
- expect(config).to include(
250
- service_name: 'gitlab-ci',
251
- service_number: service_number,
252
- service_job_number: service_job_number,
253
- service_job_id: service_job_id,
254
- service_branch: service_branch,
255
- commit_sha: commit_sha
256
- )
257
- end
258
- end
259
-
260
- describe '.define_service_params_for_semaphore' do
261
- let(:semaphore_workflow_id) { 1234 }
262
- let(:semaphore_git_pr_number) { 10 }
263
- let(:semaphore_git_working_branch) { 'pr-branch' }
264
- let(:semaphore_job_id) { 5678 }
265
- let(:semaphore_organization_url) { 'an-organization' }
266
-
267
- before do
268
- allow(ENV).to receive(:[]).with('SEMAPHORE_WORKFLOW_ID').and_return(semaphore_workflow_id)
269
- allow(ENV).to receive(:[]).with('SEMAPHORE_GIT_PR_NUMBER').and_return(semaphore_git_pr_number)
270
- allow(ENV).to receive(:[]).with('SEMAPHORE_GIT_WORKING_BRANCH').and_return(semaphore_git_working_branch)
271
- allow(ENV).to receive(:[]).with('SEMAPHORE_JOB_ID').and_return(semaphore_job_id)
272
- allow(ENV).to receive(:[]).with('SEMAPHORE_ORGANIZATION_URL').and_return(semaphore_organization_url)
273
- end
274
-
275
- it 'sets the expected parameters' do
276
- config = {}
277
- described_class.define_service_params_for_semaphore(config)
278
- expect(config).to include(
279
- service_name: 'semaphore',
280
- service_number: semaphore_workflow_id,
281
- service_job_id: semaphore_job_id,
282
- service_build_url: "#{semaphore_organization_url}/jobs/#{semaphore_job_id}",
283
- service_branch: semaphore_git_working_branch,
284
- service_pull_request: semaphore_git_pr_number
285
- )
286
- end
287
- end
288
-
289
- describe '.define_service_params_for_jenkins' do
290
- let(:service_pull_request) { '1234' }
291
- let(:build_num) { SecureRandom.hex(4) }
292
-
293
- before do
294
- allow(ENV).to receive(:[]).with('CI_PULL_REQUEST').and_return(service_pull_request)
295
- allow(ENV).to receive(:[]).with('BUILD_NUMBER').and_return(build_num)
296
- end
297
-
298
- it 'sets the expected parameters' do
299
- config = {}
300
- described_class.define_service_params_for_jenkins config
301
- described_class.define_standard_service_params_for_generic_ci config
302
- expect(config).to include(
303
- service_name: 'jenkins',
304
- service_number: build_num,
305
- service_pull_request: service_pull_request
306
- )
307
- end
308
- end
309
-
310
- describe '.define_service_params_for_coveralls_local' do
311
- it 'sets the expected parameters' do
312
- config = {}
313
- described_class.define_service_params_for_coveralls_local(config)
314
- expect(config).to include(
315
- service_name: 'coveralls-ruby',
316
- service_job_id: nil,
317
- service_event_type: 'manual'
318
- )
319
- end
320
- end
321
-
322
- describe '.define_service_params_for_generic_ci' do
323
- let(:service_name) { SecureRandom.hex(4) }
324
- let(:service_number) { SecureRandom.hex(4) }
325
- let(:service_build_url) { SecureRandom.hex(4) }
326
- let(:service_branch) { SecureRandom.hex(4) }
327
- let(:service_pull_request) { '1234' }
328
-
329
- before do
330
- allow(ENV).to receive(:[]).with('CI_NAME').and_return(service_name)
331
- allow(ENV).to receive(:[]).with('CI_BUILD_NUMBER').and_return(service_number)
332
- allow(ENV).to receive(:[]).with('CI_BUILD_URL').and_return(service_build_url)
333
- allow(ENV).to receive(:[]).with('CI_BRANCH').and_return(service_branch)
334
- allow(ENV).to receive(:[]).with('CI_PULL_REQUEST').and_return(service_pull_request)
335
- end
336
-
337
- it 'sets the expected parameters' do
338
- config = {}
339
- described_class.define_standard_service_params_for_generic_ci(config)
340
- expect(config).to include(
341
- service_name: service_name,
342
- service_number: service_number,
343
- service_build_url: service_build_url,
344
- service_branch: service_branch,
345
- service_pull_request: service_pull_request
346
- )
347
- end
348
- end
349
-
350
- describe '.define_service_params_for_appveyor' do
351
- let(:service_number) { SecureRandom.hex(4) }
352
- let(:service_branch) { SecureRandom.hex(4) }
353
- let(:commit_sha) { SecureRandom.hex(4) }
354
- let(:repo_name) { SecureRandom.hex(4) }
355
-
356
- before do
357
- allow(ENV).to receive(:[]).with('APPVEYOR_BUILD_VERSION').and_return(service_number)
358
- allow(ENV).to receive(:[]).with('APPVEYOR_REPO_BRANCH').and_return(service_branch)
359
- allow(ENV).to receive(:[]).with('APPVEYOR_REPO_COMMIT').and_return(commit_sha)
360
- allow(ENV).to receive(:[]).with('APPVEYOR_REPO_NAME').and_return(repo_name)
361
- end
362
-
363
- it 'sets the expected parameters' do
364
- config = {}
365
- described_class.define_service_params_for_appveyor(config)
366
- expect(config).to include(
367
- service_name: 'appveyor',
368
- service_number: service_number,
369
- service_branch: service_branch,
370
- commit_sha: commit_sha,
371
- service_build_url: format('https://ci.appveyor.com/project/%<repo_name>s/build/%<service_number>s', repo_name: repo_name, service_number: service_number)
372
- )
373
- end
374
- end
375
-
376
- describe '.define_service_params_for_tddium' do
377
- let(:service_number) { SecureRandom.hex(4) }
378
- let(:service_job_number) { SecureRandom.hex(4) }
379
- let(:service_pull_request) { SecureRandom.hex(4) }
380
- let(:service_branch) { SecureRandom.hex(4) }
381
-
382
- before do
383
- allow(ENV).to receive(:[]).with('TDDIUM_SESSION_ID').and_return(service_number)
384
- allow(ENV).to receive(:[]).with('TDDIUM_TID').and_return(service_job_number)
385
- allow(ENV).to receive(:[]).with('TDDIUM_PR_ID').and_return(service_pull_request)
386
- allow(ENV).to receive(:[]).with('TDDIUM_CURRENT_BRANCH').and_return(service_branch)
387
- end
388
-
389
- it 'sets the expected parameters' do
390
- config = {}
391
- described_class.define_service_params_for_tddium(config)
392
- expect(config).to include(
393
- service_name: 'tddium',
394
- service_number: service_number,
395
- service_job_number: service_job_number,
396
- service_pull_request: service_pull_request,
397
- service_branch: service_branch,
398
- service_build_url: format('https://ci.solanolabs.com/reports/%<service_number>s', service_number: service_number)
399
- )
400
- end
401
- end
402
-
403
- describe '.git' do
404
- let(:git_id) { SecureRandom.hex(2) }
405
- let(:author_name) { SecureRandom.hex(4) }
406
- let(:author_email) { SecureRandom.hex(4) }
407
- let(:committer_name) { SecureRandom.hex(4) }
408
- let(:committer_email) { SecureRandom.hex(4) }
409
- let(:message) { SecureRandom.hex(4) }
410
- let(:branch) { SecureRandom.hex(4) }
411
-
412
- before do
413
- allow(ENV).to receive(:fetch).with('GIT_ID', anything).and_return(git_id)
414
- allow(ENV).to receive(:fetch).with('GIT_AUTHOR_NAME', anything).and_return(author_name)
415
- allow(ENV).to receive(:fetch).with('GIT_AUTHOR_EMAIL', anything).and_return(author_email)
416
- allow(ENV).to receive(:fetch).with('GIT_COMMITTER_NAME', anything).and_return(committer_name)
417
- allow(ENV).to receive(:fetch).with('GIT_COMMITTER_EMAIL', anything).and_return(committer_email)
418
- allow(ENV).to receive(:fetch).with('GIT_MESSAGE', anything).and_return(message)
419
- allow(ENV).to receive(:fetch).with('GIT_BRANCH', anything).and_return(branch)
420
- end
421
-
422
- it 'uses ENV vars' do
423
- config = described_class.git
424
- expect(config[:branch]).to eq(branch)
425
- expect(config[:head]).to include(
426
- id: git_id,
427
- author_name: author_name,
428
- author_email: author_email,
429
- committer_name: committer_name,
430
- committer_email: committer_email,
431
- message: message
432
- )
433
- end
434
- end
435
- end
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Coveralls do
6
- before do
7
- allow(SimpleCov).to receive(:start)
8
- stub_api_post
9
- described_class.testing = true
10
- end
11
-
12
- describe '#will_run?' do
13
- it 'checks CI environemnt variables' do
14
- expect(described_class).to be_will_run
15
- end
16
-
17
- context 'with CI disabled' do
18
- before do
19
- allow(ENV).to receive(:[])
20
- allow(ENV).to receive(:[]).with('COVERALLS_RUN_LOCALLY').and_return(nil)
21
- allow(ENV).to receive(:[]).with('CI').and_return(nil)
22
- described_class.testing = false
23
- end
24
-
25
- it 'indicates no run' do
26
- expect(described_class).not_to be_will_run
27
- end
28
- end
29
- end
30
-
31
- describe '#should_run?' do
32
- it 'outputs to stdout when running locally' do
33
- described_class.testing = false
34
- described_class.run_locally = true
35
-
36
- expect do
37
- silence { described_class.should_run? }
38
- end.not_to raise_error
39
- end
40
- end
41
-
42
- describe '#wear!' do
43
- it 'receives block' do
44
- silence do
45
- described_class.wear! do
46
- add_filter 's'
47
- end
48
- end
49
-
50
- expect(SimpleCov).to have_received(:start)
51
- end
52
-
53
- it 'uses string' do
54
- silence do
55
- described_class.wear! 'test_frameworks'
56
- end
57
-
58
- expect(SimpleCov).to have_received(:start).with 'test_frameworks'
59
- end
60
-
61
- it 'uses default' do
62
- silence do
63
- described_class.wear!
64
- end
65
-
66
- expect(SimpleCov).to have_received(:start).with no_args
67
- expect(SimpleCov.filters.map(&:filter_argument)).to include 'vendor'
68
- end
69
- end
70
-
71
- describe '#wear_merged!' do
72
- it 'sets formatter to NilFormatter' do
73
- silence do
74
- described_class.wear_merged! 'rails' do
75
- add_filter '/spec/'
76
- end
77
- end
78
-
79
- expect(SimpleCov.formatter).to be Coveralls::NilFormatter
80
- end
81
- end
82
-
83
- describe '#push!' do
84
- let(:coverage_hash) do
85
- { 'file.rb'=>{ 'lines'=>[nil] } }
86
- end
87
-
88
- before do
89
- allow(SimpleCov::ResultMerger).to receive(:merge_valid_results).and_return([['RSpec'], coverage_hash])
90
- end
91
-
92
- it 'sends existing test results' do
93
- result = false
94
- silence do
95
- result = described_class.push!
96
- end
97
- expect(result).to be_truthy
98
- end
99
- end
100
-
101
- describe '#setup!' do
102
- it 'sets SimpleCov adapter' do
103
- previous_adapter = described_class.adapter
104
- described_class.adapter = nil
105
-
106
- expect do
107
- silence { described_class.setup! }
108
- end.to change(described_class, :adapter).from(nil).to(:simplecov)
109
- ensure
110
- described_class.adapter = previous_adapter
111
- end
112
-
113
- context 'when SimpleCov is not defined' do
114
- # rubocop:disable RSpec/LeakyConstantDeclaration
115
- it 'tries to load it' do
116
- SimpleCovTmp = SimpleCov
117
- Object.send :remove_const, :SimpleCov
118
- expect do
119
- silence { described_class.setup! }
120
- end.not_to raise_error
121
- ensure
122
- SimpleCov = SimpleCovTmp
123
- end
124
- # rubocop:enable RSpec/LeakyConstantDeclaration
125
- end
126
- end
127
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Foo class
4
- class Foo
5
- def initialize
6
- @foo = 'baz'
7
- end
8
-
9
- # :nocov:
10
- def bar
11
- @foo
12
- end
13
- # :nocov:
14
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Foo class
4
- class Foo
5
- def initialize
6
- @foo = 'baz'
7
- end
8
-
9
- def bar
10
- @foo
11
- end
12
- end
@@ -1,10 +0,0 @@
1
- # Foo class
2
- class Foo
3
- def initialize
4
- @foo = 'baz'
5
- end
6
-
7
- def bar
8
- @foo
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # Foo class
2
- class Foo
3
- def initialize
4
- @foo = 'baz'
5
- end
6
-
7
- def bar
8
- @foo
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # Foo class
2
- class Foo
3
- def initialize
4
- @foo = 'baz'
5
- end
6
-
7
- def bar
8
- @foo
9
- end
10
- end
@@ -1,16 +0,0 @@
1
- # Foo class
2
- class Foo
3
- def initialize
4
- @foo = 'baz'
5
- end
6
-
7
- def bar
8
- @foo
9
- end
10
-
11
- def foo
12
- if @foo
13
- 'bar'
14
- end
15
- end
16
- end
@@ -1 +0,0 @@
1
- # this file should not be covered
@@ -1,12 +0,0 @@
1
- # Foo class
2
- class Foo
3
- def initialize
4
- @foo = 'baz'
5
- end
6
-
7
- # :nocov:
8
- def bar
9
- @foo
10
- end
11
- # :nocov:
12
- end