/
consumer_spec.rb
556 lines (441 loc) · 19.9 KB
/
consumer_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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
require File.expand_path('../../spec_helper', __FILE__)
module Pod
describe Specification::Consumer do
describe "In general" do
before do
@spec = Spec.new do |s|
s.name = "Pod"
s.platform = :ios, '6.0'
end
@consumer = Specification::Consumer.new(@spec, :ios)
end
it "returns the specification" do
@consumer.spec.should == @spec
end
it "returns the platform" do
@consumer.platform_name.should == :ios
end
it "can be initialized with a platform instance" do
@consumer = Specification::Consumer.new(@spec, Platform.new(:ios, '6.1'))
@consumer.platform_name.class.should == Symbol
@consumer.platform_name.should == :ios
end
it "raises if the specification does not supports the given platform" do
platform = Platform.new(:ios, '4.3')
e = lambda { Specification::Consumer.new(@spec, platform) }.should.raise StandardError
e.message.should.match /not compatible with iOS 4.3/
end
end
#-------------------------------------------------------------------------#
describe "Regular attributes" do
before do
@spec = Spec.new do |s|
s.name = "Pod"
s.subspec 'Subspec' do |sp|
end
end
@subspec = @spec.subspecs.first
@consumer = Specification::Consumer.new(@spec, :ios)
@subspec_consumer = Specification::Consumer.new(@subspec, :ios)
end
#------------------#
it "allows to specify whether the specification requires ARC" do
@spec.requires_arc = true
@consumer.requires_arc?.should.be.true
end
it "doesn't requires arc by default" do
@consumer.requires_arc?.should.be.false
end
it "inherits where it requires arc from the parent" do
@spec.requires_arc = true
@subspec_consumer.requires_arc?.should.be.true
end
it "doesn't inherit whether it requires ARC from the parent if it is false" do
@spec.requires_arc = true
@subspec.requires_arc = false
@subspec_consumer.requires_arc?.should.be.false
end
#----------------#
it "allows to specify the frameworks" do
@spec.framework = %w(QuartzCore CoreData)
@consumer.frameworks.should == %w(QuartzCore CoreData)
end
it "allows to specify a single framework" do
@spec.framework = 'QuartzCore'
@consumer.frameworks.should == %w(QuartzCore)
end
it "inherits the frameworks of the parent" do
@spec.framework = 'QuartzCore'
@subspec.framework = 'CoreData'
@subspec_consumer.frameworks.should == %w(QuartzCore CoreData)
end
#------------------#
it "allows to specify the weak frameworks" do
@spec.weak_frameworks = %w(Twitter iAd)
@consumer.weak_frameworks.should == %w(Twitter iAd)
end
it "allows to specify a single weak framework" do
@spec.weak_framework = 'Twitter'
@consumer.weak_frameworks.should == %w(Twitter)
end
it "inherits the weak frameworks of the parent" do
@spec.weak_framework = 'Twitter'
@subspec.weak_framework = 'iAd'
@subspec_consumer.weak_frameworks.should == %w(Twitter iAd)
end
#------------------#
it "allows to specify the libraries" do
@spec.libraries = 'z', 'xml2'
@consumer.libraries.should == %w(z xml2)
end
it "allows to specify a single library" do
@spec.library = 'z'
@consumer.libraries.should == %w(z)
end
it "inherits the libraries from the parent" do
@spec.library = 'z'
@subspec.library = 'xml2'
@subspec_consumer.libraries.should == %w(z xml2)
end
#------------------#
it "allows to specify compiler flags" do
@spec.compiler_flags = %w(-Wdeprecated-implementations -Wunused-value)
@consumer.compiler_flags.should == %w(-Wdeprecated-implementations -Wunused-value)
end
it "allows to specify a single compiler flag" do
@spec.compiler_flag = '-Wdeprecated-implementations'
@consumer.compiler_flags.should == %w(-Wdeprecated-implementations)
end
it "inherits the compiler flags from the parent" do
@spec.compiler_flag = '-Wdeprecated-implementations'
@subspec.compiler_flag = '-Wunused-value'
@subspec_consumer.compiler_flags.should == %w(-Wdeprecated-implementations -Wunused-value)
end
it "merges the compiler flags so values for platforms can be specified" do
@spec.compiler_flags = '-Wdeprecated-implementations'
@spec.ios.compiler_flags = '-Wunused-value'
@consumer.compiler_flags.should == %w(-Wdeprecated-implementations -Wunused-value)
osx_consumer = Specification::Consumer.new(@spec, :osx)
osx_consumer.compiler_flags.should == %w(-Wdeprecated-implementations)
end
#------------------#
it "allows to specify xcconfig settings" do
@spec.xcconfig = { 'OTHER_LDFLAGS' => '-lObjC' }
@consumer.xcconfig.should == { 'OTHER_LDFLAGS' => '-lObjC' }
end
it "inherits the xcconfig values from the parent" do
@spec.xcconfig = { 'OTHER_LDFLAGS' => '-lObjC' }
@subspec.xcconfig = { 'OTHER_LDFLAGS' => '-Wl -no_compact_unwind' }
@subspec_consumer.xcconfig.should == { 'OTHER_LDFLAGS' => '-lObjC -Wl -no_compact_unwind' }
end
it "merges the xcconfig values so values for platforms can be specified" do
@spec.xcconfig = { 'OTHER_LDFLAGS' => '-lObjC' }
@spec.ios.xcconfig = { 'OTHER_LDFLAGS' => '-Wl -no_compact_unwind' }
@consumer.xcconfig.should == { 'OTHER_LDFLAGS' => '-lObjC -Wl -no_compact_unwind' }
osx_consumer = Specification::Consumer.new(@spec, :osx)
osx_consumer.xcconfig.should == { 'OTHER_LDFLAGS' => '-lObjC' }
end
#------------------#
it "allows to specify the contents of the prefix header" do
@spec.prefix_header_contents = '#import <UIKit/UIKit.h>'
@consumer.prefix_header_contents.should == '#import <UIKit/UIKit.h>'
end
it "allows to specify the contents of the prefix header as an array" do
@spec.prefix_header_contents = ['#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>']
@consumer.prefix_header_contents.should == "#import <UIKit/UIKit.h>\n#import <Foundation/Foundation.h>"
end
it "strips the indentation of the prefix headers" do
headers = <<-DESC
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
DESC
@spec.prefix_header_contents = headers
@consumer.prefix_header_contents.should == "#import <UIKit/UIKit.h>\n#import <Foundation/Foundation.h>"
end
it "inherits the contents of the prefix header" do
@spec.prefix_header_contents = '#import <UIKit/UIKit.h>'
@subspec_consumer.prefix_header_contents.should == '#import <UIKit/UIKit.h>'
end
#------------------#
it "allows to specify the path of compiler header file" do
@spec.prefix_header_file = 'iphone/include/prefix.pch'
@consumer.prefix_header_file.should == 'iphone/include/prefix.pch'
end
it "inherits the path of compiler header file from the parent" do
@spec.prefix_header_file = 'iphone/include/prefix.pch'
@subspec_consumer.prefix_header_file.should == 'iphone/include/prefix.pch'
end
#------------------#
it "allows to specify a directory to use for the headers" do
@spec.header_dir = 'Three20Core'
@consumer.header_dir.should == 'Three20Core'
end
it "inherits the directory to use for the headers from the parent" do
@spec.header_dir = 'Three20Core'
@subspec_consumer.header_dir.should == 'Three20Core'
end
#------------------#
it "allows to specify a directory to preserver the namespacing of the headers" do
@spec.header_mappings_dir = 'src/include'
@consumer.header_mappings_dir.should == 'src/include'
end
it "inherits the directory to use for the headers from the parent" do
@spec.header_mappings_dir = 'src/include'
@subspec_consumer.header_mappings_dir.should == 'src/include'
end
end
#-------------------------------------------------------------------------#
describe "File patterns attributes" do
before do
@spec = Spec.new do |s|
s.name = "Pod"
s.subspec 'Subspec' do |sp|
end
end
@subspec = @spec.subspecs.first
@consumer = Specification::Consumer.new(@spec, :ios)
@subspec_consumer = Specification::Consumer.new(@subspec, :ios)
end
it "doesn't inherits the files patterns from the parent" do
@spec.source_files = ["lib_classes/**/*"]
@subspec.source_files = ["subspec_classes/**/*"]
@subspec_consumer.source_files.should == ["subspec_classes/**/*"]
end
it "wraps strings in an array" do
@spec.source_files = "lib_classes/**/*"
@consumer.source_files.should == ["lib_classes/**/*"]
end
#------------------#
it "returns the source files" do
@spec.source_files = ["lib_classes/**/*"]
@consumer.source_files.should == ["lib_classes/**/*"]
end
#------------------#
it "returns the public headers files" do
@spec.public_header_files = ["include/**/*"]
@consumer.public_header_files.should == ["include/**/*"]
end
it "returns the public headers files" do
@spec.private_header_files = ["private/**/*"]
@consumer.private_header_files.should == ["private/**/*"]
end
#------------------#
it "returns the frameworks bundles" do
@spec.vendored_frameworks = ["MyFramework.framework", "MyOtherFramework.framework"]
@consumer.vendored_frameworks.should == ["MyFramework.framework", "MyOtherFramework.framework"]
end
#------------------#
it "returns the library files" do
@spec.vendored_libraries = ['libProj4.a', 'libJavaScriptCore.a']
@consumer.vendored_libraries.should == ['libProj4.a', 'libJavaScriptCore.a']
end
#------------------#
it "returns the resource bundles" do
@spec.resource_bundles = { 'MapBox' => 'MapView/Map/Resources/*.png' }
@consumer.resource_bundles.should == { 'MapBox' => ['MapView/Map/Resources/*.png'] }
end
it "handles multi-platform resource bundles" do
@spec.ios.resource_bundles = { 'MapBox' => 'MapView/Map/Resources/*.png' }
@consumer.resource_bundles.should == { 'MapBox' => ['MapView/Map/Resources/*.png'] }
end
it "merges multi platform resource bundles if needed" do
@spec.resource_bundles = { 'MapBox' => 'MapView/Map/Resources/*.png' }
@spec.ios.resource_bundles = { 'MapBox-iOS' => ['MapView/Map/iOS/Resources/*.png'] }
@consumer.resource_bundles.should == {
'MapBox' => ['MapView/Map/Resources/*.png'],
'MapBox-iOS' => ['MapView/Map/iOS/Resources/*.png'],
}
end
it "merges the file patterns of multi platform resource bundles if needed" do
@spec.resource_bundles = { 'MapBox' => 'MapView/Map/Resources/*.png' }
@spec.ios.resource_bundles = { 'MapBox' => ['MapView/Map/iOS/Resources/*.png'] }
@consumer.resource_bundles.should == {
'MapBox' => ['MapView/Map/Resources/*.png', 'MapView/Map/iOS/Resources/*.png'],
}
end
it "returns the empty hash if no resource bundles have been specified" do
@consumer.resource_bundles.should == {}
end
#------------------#
it "returns the resources files" do
@spec.resources = ['frameworks/CrashReporter.framework']
@consumer.resources.should == ['frameworks/CrashReporter.framework']
end
it "doesn't inherit resources from the parent" do
@spec.resources = ['parent_resources/*']
@subspec.resources = ['subspec_resources/*']
@subspec_consumer.resources.should == ['subspec_resources/*']
end
it "has a singular form for resources" do
@spec.resource = "lib_resources/file.png"
@consumer.resources.should == ["lib_resources/file.png"]
end
#------------------#
it "returns the paths to exclude" do
@spec.exclude_files = "Classes/**/unused.{h,m}"
@consumer.exclude_files.should == ["Classes/**/unused.{h,m}"]
end
#------------------#
it "returns the paths to preserve" do
@spec.preserve_paths = ["Frameworks/*.framework"]
@consumer.preserve_paths.should == ["Frameworks/*.framework"]
end
it "can accept a single path to preserve" do
@spec.preserve_path = "Frameworks/*.framework"
@consumer.preserve_paths.should == ["Frameworks/*.framework"]
end
end
#-------------------------------------------------------------------------#
describe "Dependencies" do
before do
@spec = Spec.new do |s|
s.name = "Pod"
s.dependency 'AFNetworking'
s.osx.dependency 'MagicalRecord'
s.subspec 'Subspec' do |sp|
sp.dependency 'libPusher', '1.0'
end
end
@subspec = @spec.subspecs.first
@subspec = @spec.subspecs.first
@consumer = Specification::Consumer.new(@spec, :ios)
@subspec_consumer = Specification::Consumer.new(@subspec, :ios)
end
it "returns the dependencies on other Pods for the activated platform" do
@consumer.dependencies.should == [Dependency.new('AFNetworking')]
end
it "inherits the dependencies of the parent" do
@subspec_consumer.dependencies.sort.should == [
Dependency.new('AFNetworking'), Dependency.new('libPusher', '1.0')]
end
it "takes into account the dependencies specified for a platform" do
osx_consumer = Specification::Consumer.new(@spec, :osx)
osx_consumer.dependencies.sort.should == [
Dependency.new('AFNetworking'), Dependency.new('MagicalRecord')]
end
end
#-------------------------------------------------------------------------#
describe "Private helpers" do
before do
@spec = Spec.new do |s|
s.name = "Pod"
s.source_files = "spec_files"
s.ios.source_files = "ios_files"
s.framework = 'spec_framework'
s.subspec 'Subspec' do |ss|
ss.source_files = "subspec_files"
ss.framework = 'subspec_framework'
end
end
@subspec = @spec.subspecs.first
@consumer = Specification::Consumer.new(@spec, :ios)
@subspec_consumer = Specification::Consumer.new(@subspec, :ios)
end
#--------------------------------------#
describe "#value_for_attribute" do
it "takes into account inheritance" do
@subspec_consumer.frameworks.should == %w(spec_framework subspec_framework)
end
it "takes into account multiplatform values" do
@consumer.source_files.should == %w(spec_files ios_files)
osx_consumer = Specification::Consumer.new(@spec, :osx)
osx_consumer.source_files.should == ["spec_files"]
end
it "takes into account a default value if specified" do
@consumer.requires_arc.should == false
end
it "initializes the value to the empty container if no value could be resolved" do
@consumer.libraries.should == []
end
end
#--------------------------------------#
describe "#value_with_inheritance" do
it "handles root specs" do
attr = Specification::DSL.attributes[:source_files]
value = @consumer.send(:value_with_inheritance, @spec, attr)
value.should == %w(spec_files ios_files)
end
it "takes into account the value of the parent if needed" do
attr = Specification::DSL.attributes[:frameworks]
value = @consumer.send(:value_with_inheritance, @subspec, attr)
value.should == %w(spec_framework subspec_framework)
end
it "doesn't inherits value of the parent if the attribute is not inherited" do
attr = Specification::DSL.attributes[:source_files]
attr.stubs(:inherited?).returns(false)
value = @consumer.send(:value_with_inheritance, @subspec, attr)
value.should == ["subspec_files"]
end
end
#--------------------------------------#
describe "#raw_value_for_attribute" do
it "returns the raw value as stored in the specification" do
attr = Specification::DSL.attributes[:source_files]
osx_consumer = Specification::Consumer.new(@spec, :osx)
value = osx_consumer.send(:raw_value_for_attribute, @spec, attr)
value.should == ["spec_files"]
end
it "takes into account the multi-platform values" do
attr = Specification::DSL.attributes[:source_files]
value = @consumer.send(:raw_value_for_attribute, @spec, attr)
value.should == %w(spec_files ios_files)
end
end
#--------------------------------------#
describe "#merge_values" do
it "returns the current value if the value to merge is nil" do
attr = Specification::DSL::Attribute.new(:test, { :container => Hash })
result = @consumer.send(:merge_values, attr, "value", nil)
result.should == "value"
end
it "returns the value to merge if the current value is nil" do
attr = Specification::DSL::Attribute.new(:test, { :container => Hash })
result = @consumer.send(:merge_values, attr, nil, "value")
result.should == "value"
end
it "handles boolean values" do
attr = Specification::DSL::Attribute.new(:test, { :types => [TrueClass, FalseClass] })
@consumer.send(:merge_values, attr, false, nil).should == false
@consumer.send(:merge_values, attr, false, false).should == false
@consumer.send(:merge_values, attr, false, true).should == true
@consumer.send(:merge_values, attr, true, false).should == false
end
it "concatenates the values of attributes contained in an array" do
attr = Specification::DSL::Attribute.new(:test, { :container => Array })
result = @consumer.send(:merge_values, attr, 'CoreGraphics', 'CoreData')
result.should == %w(CoreGraphics CoreData)
end
it "handles hashes while merging values" do
attr = Specification::DSL::Attribute.new(:test, { :container => Hash })
result = @consumer.send(:merge_values, attr, { :value1 => '1' }, { :value2 => '2' })
result.should == {
:value1 => '1',
:value2 => '2',
}
end
it "merges the values of the keys of hashes contained in an array" do
attr = Specification::DSL::Attribute.new(:test, { :container => Hash })
value = { :resources => %w(A B) }
value_to_mege = { :resources => 'C' }
result = @consumer.send(:merge_values, attr, value, value_to_mege)
result.should == { :resources => %w(A B C) }
end
it "merges the values of the keys of hashes contained in a string" do
attr = Specification::DSL::Attribute.new(:test, { :container => Hash })
value = { 'OTHER_LDFLAGS' => '-lObjC' }
value_to_mege = { 'OTHER_LDFLAGS' => '-framework SystemConfiguration' }
result = @consumer.send(:merge_values, attr, value, value_to_mege)
result.should == { 'OTHER_LDFLAGS' => '-lObjC -framework SystemConfiguration' }
end
it "returns the original value if the attribute is a string" do
attr = Specification::DSL::Attribute.new(:test, {})
existing_value = 'header_dir_1'
value_to_mege = 'header_dir_2'
result = @consumer.send(:merge_values, attr, existing_value, value_to_mege)
result.should == 'header_dir_2'
end
end
#--------------------------------------#
end
end
end