coveralls-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module Coveralls
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,371 @@
1
+ require 'spec_helper'
2
+
3
+ describe Coveralls::Configuration do
4
+ before do
5
+ ENV.stub(:[]).and_return(nil)
6
+ end
7
+
8
+ describe '.configuration' do
9
+ it "returns a hash with the default keys" do
10
+ config = Coveralls::Configuration.configuration
11
+ config.should be_a(Hash)
12
+ config.keys.should include(:environment)
13
+ config.keys.should include(:git)
14
+ end
15
+
16
+ context 'yaml_config' do
17
+ let(:repo_token) { SecureRandom.hex(4) }
18
+ let(:repo_secret_token) { SecureRandom.hex(4) }
19
+ let(:yaml_config) {
20
+ {
21
+ 'repo_token' => repo_token,
22
+ 'repo_secret_token' => repo_secret_token
23
+ }
24
+ }
25
+
26
+ before do
27
+ Coveralls::Configuration.stub(:yaml_config).and_return(yaml_config)
28
+ end
29
+
30
+ it 'sets the Yaml config and associated variables if present' do
31
+ config = Coveralls::Configuration.configuration
32
+ config[:configuration].should eq(yaml_config)
33
+ config[:repo_token].should eq(repo_token)
34
+ end
35
+
36
+ it 'uses the repo_secret_token if the repo_token is not set' do
37
+ yaml_config.delete('repo_token')
38
+ config = Coveralls::Configuration.configuration
39
+ config[:configuration].should eq(yaml_config)
40
+ config[:repo_token].should eq(repo_secret_token)
41
+ end
42
+ end
43
+
44
+ context 'repo_token in environment' do
45
+ let(:repo_token) { SecureRandom.hex(4) }
46
+
47
+ before do
48
+ ENV.stub(:[]).with('COVERALLS_REPO_TOKEN').and_return(repo_token)
49
+ end
50
+
51
+ it 'pulls the repo token from the environment if set' do
52
+ config = Coveralls::Configuration.configuration
53
+ config[:repo_token].should eq(repo_token)
54
+ end
55
+ end
56
+
57
+ context 'flag_name in environment' do
58
+ let(:flag_name) { 'Test Flag' }
59
+
60
+ before do
61
+ ENV.stub(:[]).with('COVERALLS_FLAG_NAME').and_return(flag_name)
62
+ end
63
+
64
+ it 'pulls the flag name from the environment if set' do
65
+ config = Coveralls::Configuration.configuration
66
+ config[:flag_name].should eq(flag_name)
67
+ end
68
+ end
69
+
70
+ context 'Services' do
71
+ context 'with env based service name' do
72
+ let(:service_name) { 'travis-enterprise' }
73
+ before do
74
+ ENV.stub(:[]).with('TRAVIS').and_return('1')
75
+ ENV.stub(:[]).with('COVERALLS_SERVICE_NAME').and_return(service_name)
76
+ end
77
+
78
+ it 'pulls the service name from the environment if set' do
79
+ config = Coveralls::Configuration.configuration
80
+ config[:service_name].should eq(service_name)
81
+ end
82
+ end
83
+
84
+ context 'on Travis' do
85
+ before do
86
+ ENV.stub(:[]).with('TRAVIS').and_return('1')
87
+ end
88
+
89
+ it 'should set service parameters for this service and no other' do
90
+ Coveralls::Configuration.should_receive(:set_service_params_for_travis).with(anything, anything)
91
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
92
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
93
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
94
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
95
+ Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci)
96
+ Coveralls::Configuration.configuration
97
+ end
98
+ end
99
+
100
+ context 'on CircleCI' do
101
+ before do
102
+ ENV.stub(:[]).with('CIRCLECI').and_return('1')
103
+ end
104
+
105
+ it 'should set service parameters for this service and no other' do
106
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
107
+ Coveralls::Configuration.should_receive(:set_service_params_for_circleci)
108
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
109
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
110
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
111
+ Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci)
112
+ Coveralls::Configuration.configuration
113
+ end
114
+ end
115
+
116
+ context 'on Semaphore' do
117
+ before do
118
+ ENV.stub(:[]).with('SEMAPHORE').and_return('1')
119
+ end
120
+
121
+ it 'should set service parameters for this service and no other' do
122
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
123
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
124
+ Coveralls::Configuration.should_receive(:set_service_params_for_semaphore)
125
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
126
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
127
+ Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci)
128
+ Coveralls::Configuration.configuration
129
+ end
130
+ end
131
+
132
+ context 'when using Jenkins' do
133
+ before do
134
+ ENV.stub(:[]).with('JENKINS_URL').and_return('1')
135
+ end
136
+
137
+ it 'should set service parameters for this service and no other' do
138
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
139
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
140
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
141
+ Coveralls::Configuration.should_receive(:set_service_params_for_jenkins)
142
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
143
+ Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci)
144
+ Coveralls::Configuration.configuration
145
+ end
146
+ end
147
+
148
+ context 'when running Coveralls locally' do
149
+ before do
150
+ ENV.stub(:[]).with('COVERALLS_RUN_LOCALLY').and_return('1')
151
+ end
152
+
153
+ it 'should set service parameters for this service and no other' do
154
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
155
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
156
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
157
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
158
+ Coveralls::Configuration.should_receive(:set_service_params_for_coveralls_local)
159
+ Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci)
160
+ Coveralls::Configuration.configuration
161
+ end
162
+ end
163
+
164
+ context 'for generic CI' do
165
+ before do
166
+ ENV.stub(:[]).with('CI_NAME').and_return('1')
167
+ end
168
+
169
+ it 'should set service parameters for this service and no other' do
170
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
171
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
172
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
173
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
174
+ Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
175
+ Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci).with(anything)
176
+ Coveralls::Configuration.configuration
177
+ end
178
+ end
179
+ end
180
+ end
181
+
182
+ describe '.set_service_params_for_travis' do
183
+ let(:travis_job_id) { SecureRandom.hex(4) }
184
+ before do
185
+ ENV.stub(:[]).with('TRAVIS_JOB_ID').and_return(travis_job_id)
186
+ end
187
+
188
+ it 'should set the service_job_id' do
189
+ config = {}
190
+ Coveralls::Configuration.set_service_params_for_travis(config, nil)
191
+ config[:service_job_id].should eq(travis_job_id)
192
+ end
193
+
194
+ it 'should set the service_name to travis-ci by default' do
195
+ config = {}
196
+ Coveralls::Configuration.set_service_params_for_travis(config, nil)
197
+ config[:service_name].should eq('travis-ci')
198
+ end
199
+
200
+ it 'should set the service_name to a value if one is passed in' do
201
+ config = {}
202
+ random_name = SecureRandom.hex(4)
203
+ Coveralls::Configuration.set_service_params_for_travis(config, random_name)
204
+ config[:service_name].should eq(random_name)
205
+ end
206
+ end
207
+
208
+ describe '.set_service_params_for_circleci' do
209
+ let(:circle_build_num) { SecureRandom.hex(4) }
210
+ before do
211
+ ENV.stub(:[]).with('CIRCLE_BUILD_NUM').and_return(circle_build_num)
212
+ end
213
+
214
+ it 'should set the expected parameters' do
215
+ config = {}
216
+ Coveralls::Configuration.set_service_params_for_circleci(config)
217
+ config[:service_name].should eq('circleci')
218
+ config[:service_number].should eq(circle_build_num)
219
+ end
220
+ end
221
+
222
+ describe '.set_service_params_for_gitlab' do
223
+ let(:commit_sha) { SecureRandom.hex(32) }
224
+ let(:service_job_number) { "spec:one" }
225
+ let(:service_job_id) { 1234 }
226
+ let(:service_branch) { "feature" }
227
+ let(:service_number) { 5678 }
228
+
229
+ before do
230
+ ENV.stub(:[]).with('CI_BUILD_NAME').and_return(service_job_number)
231
+ ENV.stub(:[]).with('CI_PIPELINE_ID').and_return(service_number)
232
+ ENV.stub(:[]).with('CI_BUILD_ID').and_return(service_job_id)
233
+ ENV.stub(:[]).with('CI_BUILD_REF_NAME').and_return(service_branch)
234
+ ENV.stub(:[]).with('CI_BUILD_REF').and_return(commit_sha)
235
+ end
236
+
237
+ it 'should set the expected parameters' do
238
+ config = {}
239
+ Coveralls::Configuration.set_service_params_for_gitlab(config)
240
+ config[:service_name].should eq('gitlab-ci')
241
+ config[:service_number].should eq(service_number)
242
+ config[:service_job_number].should eq(service_job_number)
243
+ config[:service_job_id].should eq(service_job_id)
244
+ config[:service_branch].should eq(service_branch)
245
+ config[:commit_sha].should eq(commit_sha)
246
+ end
247
+ end
248
+
249
+ describe '.set_service_params_for_semaphore' do
250
+ let(:semaphore_build_num) { SecureRandom.hex(4) }
251
+ before do
252
+ ENV.stub(:[]).with('SEMAPHORE_BUILD_NUMBER').and_return(semaphore_build_num)
253
+ end
254
+
255
+ it 'should set the expected parameters' do
256
+ config = {}
257
+ Coveralls::Configuration.set_service_params_for_semaphore(config)
258
+ config[:service_name].should eq('semaphore')
259
+ config[:service_number].should eq(semaphore_build_num)
260
+ end
261
+ end
262
+
263
+ describe '.set_service_params_for_jenkins' do
264
+ let(:service_pull_request) { '1234' }
265
+ let(:build_num) { SecureRandom.hex(4) }
266
+ before do
267
+ ENV.stub(:[]).with('CI_PULL_REQUEST').and_return(service_pull_request)
268
+ ENV.stub(:[]).with('BUILD_NUMBER').and_return(build_num)
269
+ end
270
+
271
+ it 'should set the expected parameters' do
272
+ config = {}
273
+ Coveralls::Configuration.set_service_params_for_jenkins(config)
274
+ Coveralls::Configuration.set_standard_service_params_for_generic_ci(config)
275
+ config[:service_name].should eq('jenkins')
276
+ config[:service_number].should eq(build_num)
277
+ config[:service_pull_request].should eq(service_pull_request)
278
+ end
279
+ end
280
+
281
+ describe '.set_service_params_for_coveralls_local' do
282
+ it 'should set the expected parameters' do
283
+ config = {}
284
+ Coveralls::Configuration.set_service_params_for_coveralls_local(config)
285
+ config[:service_name].should eq('coveralls-ruby')
286
+ config[:service_job_id].should be_nil
287
+ config[:service_event_type].should eq('manual')
288
+ end
289
+ end
290
+
291
+ describe '.set_service_params_for_generic_ci' do
292
+ let(:service_name) { SecureRandom.hex(4) }
293
+ let(:service_number) { SecureRandom.hex(4) }
294
+ let(:service_build_url) { SecureRandom.hex(4) }
295
+ let(:service_branch) { SecureRandom.hex(4) }
296
+ let(:service_pull_request) { '1234' }
297
+
298
+ before do
299
+ ENV.stub(:[]).with('CI_NAME').and_return(service_name)
300
+ ENV.stub(:[]).with('CI_BUILD_NUMBER').and_return(service_number)
301
+ ENV.stub(:[]).with('CI_BUILD_URL').and_return(service_build_url)
302
+ ENV.stub(:[]).with('CI_BRANCH').and_return(service_branch)
303
+ ENV.stub(:[]).with('CI_PULL_REQUEST').and_return(service_pull_request)
304
+ end
305
+
306
+ it 'should set the expected parameters' do
307
+ config = {}
308
+ Coveralls::Configuration.set_standard_service_params_for_generic_ci(config)
309
+ config[:service_name].should eq(service_name)
310
+ config[:service_number].should eq(service_number)
311
+ config[:service_build_url].should eq(service_build_url)
312
+ config[:service_branch].should eq(service_branch)
313
+ config[:service_pull_request].should eq(service_pull_request)
314
+ end
315
+ end
316
+
317
+ describe '.set_service_params_for_appveyor' do
318
+ let(:service_number) { SecureRandom.hex(4) }
319
+ let(:service_branch) { SecureRandom.hex(4) }
320
+ let(:commit_sha) { SecureRandom.hex(4) }
321
+ let(:repo_name) { SecureRandom.hex(4) }
322
+
323
+ before do
324
+ ENV.stub(:[]).with('APPVEYOR_BUILD_VERSION').and_return(service_number)
325
+ ENV.stub(:[]).with('APPVEYOR_REPO_BRANCH').and_return(service_branch)
326
+ ENV.stub(:[]).with('APPVEYOR_REPO_COMMIT').and_return(commit_sha)
327
+ ENV.stub(:[]).with('APPVEYOR_REPO_NAME').and_return(repo_name)
328
+ end
329
+
330
+ it 'should set the expected parameters' do
331
+ config = {}
332
+ Coveralls::Configuration.set_service_params_for_appveyor(config)
333
+ config[:service_name].should eq('appveyor')
334
+ config[:service_number].should eq(service_number)
335
+ config[:service_branch].should eq(service_branch)
336
+ config[:commit_sha].should eq(commit_sha)
337
+ config[:service_build_url].should eq('https://ci.appveyor.com/project/%s/build/%s' % [repo_name, service_number])
338
+ end
339
+ end
340
+
341
+ describe '.git' do
342
+ let(:git_id) { SecureRandom.hex(2) }
343
+ let(:author_name) { SecureRandom.hex(4) }
344
+ let(:author_email) { SecureRandom.hex(4) }
345
+ let(:committer_name) { SecureRandom.hex(4) }
346
+ let(:committer_email) { SecureRandom.hex(4) }
347
+ let(:message) { SecureRandom.hex(4) }
348
+ let(:branch) { SecureRandom.hex(4) }
349
+
350
+ before do
351
+ allow(ENV).to receive(:fetch).with('GIT_ID', anything).and_return(git_id)
352
+ allow(ENV).to receive(:fetch).with('GIT_AUTHOR_NAME', anything).and_return(author_name)
353
+ allow(ENV).to receive(:fetch).with('GIT_AUTHOR_EMAIL', anything).and_return(author_email)
354
+ allow(ENV).to receive(:fetch).with('GIT_COMMITTER_NAME', anything).and_return(committer_name)
355
+ allow(ENV).to receive(:fetch).with('GIT_COMMITTER_EMAIL', anything).and_return(committer_email)
356
+ allow(ENV).to receive(:fetch).with('GIT_MESSAGE', anything).and_return(message)
357
+ allow(ENV).to receive(:fetch).with('GIT_BRANCH', anything).and_return(branch)
358
+ end
359
+
360
+ it 'uses ENV vars' do
361
+ config = Coveralls::Configuration.git
362
+ config[:head][:id].should eq(git_id)
363
+ config[:head][:author_name].should eq(author_name)
364
+ config[:head][:author_email].should eq(author_email)
365
+ config[:head][:committer_name].should eq(committer_name)
366
+ config[:head][:committer_email].should eq(committer_email)
367
+ config[:head][:message].should eq(message)
368
+ config[:branch].should eq(branch)
369
+ end
370
+ end
371
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Coveralls do
4
+ before do
5
+ SimpleCov.stub(:start)
6
+ stub_api_post
7
+ Coveralls.testing = true
8
+ end
9
+
10
+ describe "#will_run?" do
11
+ it "checks CI environemnt variables" do
12
+ Coveralls.will_run?.should be_truthy
13
+ end
14
+
15
+ context "with CI disabled" do
16
+ before do
17
+ @ci = ENV['CI']
18
+ ENV['CI'] = nil
19
+ @coveralls_run_locally = ENV['COVERALLS_RUN_LOCALLY']
20
+ ENV['COVERALLS_RUN_LOCALLY'] = nil
21
+
22
+ Coveralls.testing = false
23
+ end
24
+
25
+ after do
26
+ ENV['CI'] = @ci
27
+ ENV['COVERALLS_RUN_LOCALLY'] = @coveralls_run_locally
28
+ end
29
+
30
+ it "indicates no run" do
31
+ Coveralls.will_run?.should be_falsy
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#should_run?" do
37
+ it "outputs to stdout when running locally" do
38
+ Coveralls.testing = false
39
+ Coveralls.run_locally = true
40
+ silence do
41
+ Coveralls.should_run?
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#wear!" do
47
+ it "receives block" do
48
+ ::SimpleCov.should_receive(:start)
49
+ silence do
50
+ subject.wear! do
51
+ add_filter 's'
52
+ end
53
+ end
54
+ end
55
+
56
+ it "uses string" do
57
+ ::SimpleCov.should_receive(:start).with 'test_frameworks'
58
+ silence do
59
+ subject.wear! 'test_frameworks'
60
+ end
61
+ end
62
+
63
+ it "uses default" do
64
+ ::SimpleCov.should_receive(:start).with no_args
65
+ silence do
66
+ subject.wear!
67
+ end
68
+ ::SimpleCov.filters.map(&:filter_argument).should include 'vendor'
69
+ end
70
+ end
71
+
72
+ describe "#wear_merged!" do
73
+ it "sets formatter to NilFormatter" do
74
+ ::SimpleCov.should_receive(:start).with 'rails'
75
+ silence do
76
+ subject.wear_merged! 'rails' do
77
+ add_filter "/spec/"
78
+ end
79
+ end
80
+ ::SimpleCov.formatter.should be Coveralls::NilFormatter
81
+ end
82
+ end
83
+
84
+ describe "#push!" do
85
+ it "sends existing test results", :if => RUBY_VERSION >= "1.9" do
86
+ result = false
87
+ silence do
88
+ result = subject.push!
89
+ end
90
+ result.should be_truthy
91
+ end
92
+ end
93
+
94
+ describe "#setup!" do
95
+ it "sets SimpleCov adapter" do
96
+ SimpleCovTmp = SimpleCov
97
+ Object.send :remove_const, :SimpleCov
98
+ silence { subject.setup! }
99
+ SimpleCov = SimpleCovTmp
100
+ end
101
+ end
102
+
103
+ after(:all) do
104
+ setup_formatter
105
+ end
106
+ end