-
Notifications
You must be signed in to change notification settings - Fork 340
/
specification_spec.rb
458 lines (378 loc) · 15.1 KB
/
specification_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
require File.expand_path('../spec_helper', __FILE__)
module Pod
describe Specification do
describe 'In general' do
before do
@spec = Spec.new do |s|
s.name = 'Pod'
s.version = '1.0'
s.subspec 'Subspec' do |sp|
end
end
@subspec = @spec.subspecs.first
end
it 'returns the parent' do
@subspec.parent.should == @spec
end
it 'returns the attributes hash' do
@spec.attributes_hash.should == { 'name' => 'Pod', 'version' => '1.0' }
@subspec.attributes_hash.should == { 'name' => 'Subspec' }
end
it 'returns the subspecs' do
@spec.subspecs.should == [@subspec]
end
it 'returns whether it is equal to another specification' do
@spec.should == @spec
end
it 'is not equal to another specification if the name is different' do
@spec.should.not == Spec.new { |s| s.name = 'Seed'; s.version = '1.0' }
end
it 'is not equal to another specification if the version if different' do
@spec.should.not == Spec.new { |s| s.name = 'Pod'; s.version = '2.0' }
end
it 'is equal to another if the name and the version match regardless of the attributes' do
@spec.should == Spec.new { |s| s.name = 'Pod'; s.version = '1.0'; s.source_files = 'Classes' }
end
it 'provides support for Array#uniq' do
spec_1 = Spec.new { |s| s.name = 'Pod'; s.version = '1.0' }
spec_2 = Spec.new { |s| s.name = 'Pod'; s.version = '1.0' }
[spec_1, spec_2].uniq.count.should == 1
end
it 'provides support for being used as a the key of a Hash' do
spec_1 = Spec.new { |s| s.name = 'Pod'; s.version = '1.0' }
spec_2 = Spec.new { |s| s.name = 'Pod'; s.version = '1.0' }
hash = {}
hash[spec_1] = 'VALUE_1'
hash[spec_2] = 'VALUE_2'
hash[spec_1].should == 'VALUE_2'
end
it 'produces a string representation suitable for UI output.' do
@spec.to_s.should == 'Pod (1.0)'
end
it 'handles the case where no version is available in the string representation' do
spec_1 = Spec.new { |s| s.name = 'Pod' }
spec_1.to_s.should == 'Pod'
end
it 'handles the case where no name is available in the string representation' do
spec_1 = Spec.new
spec_1.to_s.should == 'No-name'
end
it 'returns the name and the version of a Specification from its #to_s output' do
name, version = Specification.name_and_version_from_string('libPusher (1.0)')
name.should == 'libPusher'
version.should == Version.new('1.0')
end
it 'takes into account head information while returning the name and the version' do
name, version = Specification.name_and_version_from_string('libPusher (HEAD based on 1.0)')
name.should == 'libPusher'
version.should == Version.new('HEAD based on 1.0')
end
it 'takes into account the full name of the subspec returning the name and the version' do
string = 'RestKit/JSON (1.0)'
name = Specification.name_and_version_from_string(string).first
name.should == 'RestKit/JSON'
end
it 'raises if an invalid string representation is provided' do
should.raise Informative do
Specification.name_and_version_from_string('missing_version')
end.message.should.match /Invalid string representation/
end
it 'returns the root name of a given specification name' do
Specification.root_name('Pod').should == 'Pod'
Specification.root_name('Pod/Subspec').should == 'Pod'
end
end
#-------------------------------------------------------------------------#
describe 'Hierarchy' do
before do
@spec = Spec.new do |s|
s.name = 'Pod'
s.subspec 'Subspec' do |sp|
end
end
@subspec = @spec.subspecs.first
end
it 'returns the root spec' do
@spec.root.should == @spec
@subspec.root.should == @spec
end
it 'returns whether it is a root spec' do
@spec.root?.should.be.true
@subspec.root?.should.be.false
end
it 'returns whether it is a subspec' do
@spec.subspec?.should.be.false
@subspec.subspec?.should.be.true
end
end
#-------------------------------------------------------------------------#
describe 'Dependencies' do
before do
@spec = Spec.new do |s|
s.name = 'Pod'
s.version = '1.0'
s.dependency 'AFNetworking'
s.osx.dependency 'MagicalRecord'
s.subspec 'Subspec' do |sp|
sp.dependency 'libPusher'
sp.subspec 'Subsubspec' do |ssp|
end
end
s.subspec 'SubspecOSX' do |sp|
sp.platform = :osx
end
s.subspec 'SubspeciOS' do |sp|
sp.platform = :ios
end
end
@subspec = @spec.subspecs[0]
@subspec_osx = @spec.subspecs[1]
@subspec_ios = @spec.subspecs[2]
@subsubspec = @subspec.subspecs.first
end
it 'returns the recursive subspecs' do
@spec.recursive_subspecs.sort_by(&:name).should == [@subspec, @subsubspec, @subspec_osx, @subspec_ios]
end
it 'returns a subspec given the absolute name' do
@spec.subspec_by_name('Pod/Subspec').should == @subspec
@spec.subspec_by_name('Pod/Subspec/Subsubspec').should == @subsubspec
end
it 'returns a subspec given the relative name' do
@subspec.subspec_by_name('Subspec/Subsubspec').should == @subsubspec
end
it "raises if it can't find a subspec with the given name" do
lambda { @spec.subspec_by_name('Pod/Nonexistent') }.should.raise Informative
end
it 'returns the default subspecs' do
@spec.default_subspecs = 'Subspec1', 'Subspec2'
@spec.default_subspecs.should == %w(Subspec1 Subspec2)
end
it 'returns the dependencies on its subspecs' do
@spec.subspec_dependencies.sort.should == [
Dependency.new('Pod/Subspec'),
Dependency.new('Pod/SubspecOSX'),
Dependency.new('Pod/SubspeciOS')]
end
it 'returns the dependencies on its subspecs for a given platform' do
@spec.subspec_dependencies(:ios).should == [
Dependency.new('Pod/Subspec'),
Dependency.new('Pod/SubspeciOS'),
]
end
it 'returns a dependency on a default subspecs if it is specified' do
@spec.default_subspecs = 'Subspec', 'SubspeciOS'
@spec.subspec_dependencies.should == [
Dependency.new('Pod/Subspec'),
Dependency.new('Pod/SubspeciOS'),
]
end
it 'returns all the dependencies' do
@spec.dependencies.sort.should == [
Dependency.new('AFNetworking'),
Dependency.new('MagicalRecord')]
end
it 'returns the dependencies given the platform' do
@spec.dependencies(:ios).sort.should == [Dependency.new('AFNetworking')]
end
it 'inherits the dependencies of the parent' do
@subsubspec.dependencies(:ios).sort.should == [Dependency.new('AFNetworking'), Dependency.new('libPusher')]
end
it 'returns all the dependencies including the ones on subspecs given a platform' do
@spec.all_dependencies.sort.should == [
Dependency.new('AFNetworking'),
Dependency.new('MagicalRecord'),
Dependency.new('Pod/Subspec'),
Dependency.new('Pod/SubspecOSX'),
Dependency.new('Pod/SubspeciOS')]
end
it 'returns all the dependencies for a given platform' do
@spec.all_dependencies(:ios).sort.should == [
Dependency.new('AFNetworking'),
Dependency.new('Pod/Subspec'),
Dependency.new('Pod/SubspeciOS')]
end
end
#-------------------------------------------------------------------------#
describe 'DSL Helpers' do
before do
@spec = Spec.new do |s|
s.name = 'Pod'
s.version = '1.0'
s.subspec 'Subspec' do |sp|
end
end
@subspec = @spec.subspecs.first
end
it 'reports if it is locally sourced' do
@spec.source = { 'path' => '/tmp/local/path' }
@spec.local?.should.be.true
end
it '[0.18 backwards compatibility] reports if it is locally sourced' do
@spec.source = { 'local' => '/tmp/local/path' }
@spec.local?.should.be.true
end
it 'returns whether it is supported on a given platform' do
@spec.platform = :ios, '4.0'
@spec.supported_on_platform?(:ios).should.be.true
@spec.supported_on_platform?(:ios, '4.0').should.be.true
@spec.supported_on_platform?(:ios, '3.0').should.be.false
@spec.supported_on_platform?(:osx).should.be.false
@spec.supported_on_platform?(:osx, '10.5').should.be.false
end
it 'returns the available platforms for which the pod is supported' do
@spec.platform = :ios, '4.0'
@spec.available_platforms.should == [Platform.new(:ios, '4.0')]
end
it 'inherits the name of the supported platforms from the parent' do
@spec.platform = :ios, '4.0'
@subspec.available_platforms.should == [Platform.new(:ios, '4.0')]
end
it 'returns the deployment target for the given platform' do
@spec.platform = :ios, '4.0'
@spec.deployment_target(:ios).should == '4.0'
end
it 'allows a subspec to override the deployment target of the parent' do
@spec.platform = :ios, '4.0'
@subspec.ios.deployment_target = '5.0'
@subspec.deployment_target(:ios).should == '5.0'
end
it 'inherits the deployment target from the parent' do
@spec.platform = :ios, '4.0'
@subspec.deployment_target(:ios).should == '4.0'
end
it 'returns the names of the supported platforms as specified by the user' do
@spec.platform = :ios, '4.0'
@spec.send(:supported_platform_names).should == ['ios']
end
it 'inherits the supported platform from the parent' do
@spec.platform = :ios
@subspec.send(:supported_platform_names).should == ['ios']
end
it 'returns the consumer for the given symbolic name of a platform' do
@spec.ios.source_files = 'ios-files'
consumer = @spec.consumer(:ios)
consumer.spec.should == @spec
consumer.platform_name.should == :ios
consumer.source_files.should == ['ios-files']
end
it 'returns the consumer of a given platform' do
consumer = @spec.consumer(Platform.new :ios)
consumer.spec.should == @spec
consumer.platform_name.should == :ios
end
it 'caches the consumers per platform' do
@spec.consumer(:ios).should.equal @spec.consumer(:ios)
@spec.consumer(:ios).platform_name.should == :ios
@spec.consumer(:osx).platform_name.should == :osx
end
end
#-------------------------------------------------------------------------#
describe 'Hooks' do
before do
@spec = Spec.new
end
it 'it executes the pre install hook and returns whether it was executed' do
@spec.pre_install!(nil, nil).should == FALSE
@spec.pre_install { ; }
@spec.pre_install!(nil, nil).should == TRUE
end
it 'it executes the post install hook and returns whether it was executed' do
@spec.post_install!(nil).should == FALSE
@spec.post_install { ; }
@spec.post_install!(nil).should == TRUE
end
end
#-------------------------------------------------------------------------#
describe 'DSL Attribute writers' do
before do
@spec = Spec.new
end
it 'stores the value of an attribute' do
@spec.store_attribute(:attribute, 'value')
@spec.attributes_hash.should == {
'name' => nil,
'attribute' => 'value'
}
end
it 'stores the value of an attribute for a given platform' do
@spec.store_attribute(:attribute, 'value', :ios)
@spec.attributes_hash.should == {
'name' => nil,
'ios' => { 'attribute' => 'value' }
}
end
it 'converts the keys of the hashes to a string' do
@spec.store_attribute(:attribute, :key => 'value')
@spec.attributes_hash.should == {
'name' => nil,
'attribute' => { 'key' => 'value' }
}
end
it 'declares attribute writer methods' do
Specification::DSL.attributes.values.each do |attr|
@spec.send(attr.writer_name, 'a_value')
@spec.attributes_hash[attr.name.to_s].should == 'a_value'
end
end
it 'supports the singular form of attribute writer methods' do
singular_attrs = Specification::DSL.attributes.values.select { |a| a.writer_singular_form }
singular_attrs.each do |attr|
@spec.send(attr.writer_name, 'a_value')
@spec.attributes_hash[attr.name.to_s].should == 'a_value'
end
end
end
#-------------------------------------------------------------------------#
describe 'Initialization from a file' do
it 'can be initialized from a file' do
spec = Spec.from_file(fixture('BananaLib.podspec'))
spec.class.should == Spec
spec.name.should == 'BananaLib'
end
it 'can be initialized from a JSON file' do
spec = Spec.from_file(fixture('BananaLib.podspec.json'))
spec.class.should == Spec
spec.name.should == 'BananaLib'
end
it "presents an informative if the given file file doesn't exits" do
should.raise Informative do
Spec.from_file('Missing.podspec')
end.message.should.match /No podspec exists/
end
it "presents an informative if it can't handle the specification format" do
Pathname.any_instance.stubs(:exist?).returns(true)
File.stubs(:open).returns('')
should.raise Informative do
Spec.from_file('Missing.podspec.csv')
end.message.should.match /Unsupported specification format/
end
#--------------------------------------#
before do
@path = fixture('BananaLib.podspec')
@spec = Spec.from_file(@path)
end
it 'returns the checksum of the file in which it is defined' do
@spec.checksum.should == '1b6fff3413356e7975ad0852ab380d59e3929ffa'
end
it 'returns a nil checksum if the specification is not defined in a file' do
spec = Spec.new
spec.checksum.should.be.nil
end
it 'reports the file from which it was initialized' do
@spec.defined_in_file.should == @path
end
it 'raises if there is an attempt to set the file in which the spec is defined for a subspec' do
spec = Spec.new do |s|
s.name = 'Pod'
s.version = '1.0'
s.subspec 'Subspec' do |sp|
end
end
should.raise StandardError do
spec.subspecs.first.defined_in_file = 'Some-file'
end.message.should.match /can be set only for root specs/
end
end
#-------------------------------------------------------------------------#
end
end