/
integration_spec.rb
343 lines (290 loc) · 12.7 KB
/
integration_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
require File.expand_path('../spec_helper', __FILE__)
require 'yaml'
module SpecHelper
class Installer < Pod::Installer
# Here we override the `source' of the pod specifications to point to the integration fixtures.
def dependent_specification_sets
@dependent_specification_sets ||= super
@dependent_specification_sets.each do |set|
def set.specification
spec = super
unless spec.part_of_other_pod?
source = spec.source
source[:git] = SpecHelper.fixture("integration/#{spec.name}").to_s
spec.source = source
end
spec
end
end
@dependent_specification_sets
end
end
end
unless SpecHelper.fixture('integration/ASIHTTPRequest/Classes').exist?
puts "[!] You must run `git submodule update --init` for the integration spec to work, skipping."
else
[:ios, :osx].each do |platform|
describe "A full (integration spec) installation for platform `#{platform}'" do
extend SpecHelper::TemporaryDirectory
before do
Pod::Source.reset!
Pod::Spec::Set.reset!
fixture('spec-repos/master') # ensure the archive is unpacked
@config_before = config
Pod::Config.instance = nil
config.silent = true
config.repos_dir = fixture('spec-repos')
config.project_root = temporary_directory
end
after do
Pod::Config.instance = @config_before
end
def should_successfully_perform(command)
output = `#{command} 2>&1`
puts output unless $?.success?
$?.should.be.success
end
# Lame way to run on one platform only
if platform == :ios
it "installs a Pod directly from its repo" do
url = fixture('integration/sstoolkit').to_s
commit = '2adcd0f81740d6b0cd4589af98790eee3bd1ae7b'
podfile = Pod::Podfile.new do
self.platform :ios
dependency 'SSToolkit', :git => url, :commit => commit
end
# Note that we are *not* using the stubbed SpecHelper::Installer subclass.
installer = Pod::Installer.new(podfile)
installer.install!
YAML.load(installer.lock_file.read).should == {
'PODS' => ['SSToolkit (0.1.3)'],
'DEPENDENCIES' => ["SSToolkit (from `#{url}', commit `#{commit}')"]
}
Dir.chdir(config.project_pods_root + 'SSToolkit') do
`git config --get remote.origin.url`.strip.should == url
end
end
it "installs a library with a podspec outside of the repo" do
url = 'https://raw.github.com/gist/1349824/3ec6aa60c19113573fc48eac19d0fafd6a69e033/Reachability.podspec'
podfile = Pod::Podfile.new do
self.platform :ios
# TODO use a local file instead of http?
dependency 'Reachability', :podspec => url
end
installer = SpecHelper::Installer.new(podfile)
installer.install!
YAML.load(installer.lock_file.read).should == {
'PODS' => [{ 'Reachability (1.2.3)' => ["ASIHTTPRequest (>= 1.8)"] }],
'DOWNLOAD_ONLY' => ["ASIHTTPRequest (1.8.1)"],
'DEPENDENCIES' => ["Reachability (from `#{url}')"]
}
end
it "installs a library with a podspec defined inline" do
podfile = Pod::Podfile.new do
self.platform :ios
dependency do |s|
s.name = 'JSONKit'
s.version = '1.2'
s.source = { :git => SpecHelper.fixture('integration/JSONKit').to_s, :tag => 'v1.2' }
s.source_files = 'JSONKit.*'
end
dependency do |s|
s.name = 'SSZipArchive'
s.version = '0.1.0'
s.source = { :git => SpecHelper.fixture('integration/SSZipArchive').to_s, :tag => '0.1.0' }
s.source_files = 'SSZipArchive.*', 'minizip/*.{h,c}'
end
end
installer = SpecHelper::Installer.new(podfile)
installer.install!
YAML.load(installer.lock_file.read).should == {
'PODS' => ['JSONKit (1.2)', 'SSZipArchive (0.1.0)'],
'DEPENDENCIES' => ["JSONKit (defined in Podfile)", "SSZipArchive (defined in Podfile)"]
}
change_log = (config.project_pods_root + 'JSONKit/CHANGELOG.md').read
change_log.should.include '1.2'
change_log.should.not.include '1.3'
end
end
before do
FileUtils.cp_r(fixture('integration/.'), config.project_pods_root)
end
it "runs the optional post_install callback defined in the Podfile _before_ the project is saved to disk" do
podfile = Pod::Podfile.new do
config.rootspec = self
self.platform platform
dependency 'SSZipArchive'
post_install do |installer|
target = installer.project.targets.first
target.buildConfigurations.each do |config|
config.buildSettings['GCC_ENABLE_OBJC_GC'] = 'supported'
end
end
end
SpecHelper::Installer.new(podfile).install!
project = Xcodeproj::Project.new(config.project_pods_root + 'Pods.xcodeproj')
project.targets.first.buildConfigurations.map do |config|
config.buildSettings['GCC_ENABLE_OBJC_GC']
end.should == %w{ supported supported }
end
# TODO add a simple source file which uses the compiled lib to check that it really really works
it "should activate required pods and create a working static library xcode project" do
spec = Pod::Podfile.new do
# first ensure that the correct info is available to the specs when they load
config.rootspec = self
self.platform platform
dependency 'Reachability', '< 2.0.5' if platform == :ios
dependency 'ASIWebPageRequest', '>= 1.8.1'
dependency 'JSONKit', '>= 1.0'
dependency 'SSZipArchive', '< 2'
end
installer = SpecHelper::Installer.new(spec)
installer.install!
lock_file_contents = {
'PODS' => [
{ 'ASIHTTPRequest (1.8.1)' => ["Reachability"] },
{ 'ASIWebPageRequest (1.8.1)' => ["ASIHTTPRequest (= 1.8.1)"] },
'JSONKit (1.4)',
{ 'Reachability (2.0.4)' => ["ASIHTTPRequest (>= 1.8)"] },
'SSZipArchive (0.1.1)',
],
'DEPENDENCIES' => [
"ASIWebPageRequest (>= 1.8.1)",
"JSONKit (>= 1.0)",
"Reachability (< 2.0.5)",
"SSZipArchive (< 2)",
]
}
unless platform == :ios
# No Reachability is required by ASIHTTPRequest on OSX
lock_file_contents['DEPENDENCIES'].delete_at(2)
lock_file_contents['PODS'].delete_at(3)
lock_file_contents['PODS'][0] = 'ASIHTTPRequest (1.8.1)'
end
YAML.load(installer.lock_file.read).should == lock_file_contents
root = config.project_pods_root
(root + 'Pods.xcconfig').read.should == installer.target_installers.first.xcconfig.to_s
project_file = (root + 'Pods.xcodeproj/project.pbxproj').to_s
NSDictionary.dictionaryWithContentsOfFile(project_file).should == installer.project.to_hash
puts "\n[!] Compiling static library..."
Dir.chdir(config.project_pods_root) do
should_successfully_perform "xcodebuild"
end
end
if platform == :ios
it "does not activate pods that are only part of other pods" do
spec = Pod::Podfile.new do
# first ensure that the correct info is available to the specs when they load
config.rootspec = self
self.platform platform
dependency 'Reachability', '2.0.4' # only 2.0.4 is part of ASIHTTPRequest’s source.
end
installer = SpecHelper::Installer.new(spec)
installer.install!
YAML.load(installer.lock_file.read).should == {
'PODS' => [{ 'Reachability (2.0.4)' => ["ASIHTTPRequest (>= 1.8)"] }],
'DOWNLOAD_ONLY' => ["ASIHTTPRequest (1.8.1)"],
'DEPENDENCIES' => ["Reachability (= 2.0.4)"]
}
end
end
it "adds resources to the xcode copy script" do
spec = Pod::Podfile.new do
# first ensure that the correct info is available to the specs when they load
config.rootspec = self
self.platform platform
dependency 'SSZipArchive'
end
installer = SpecHelper::Installer.new(spec)
installer.target_installers.first.build_specifications.first.resources = 'LICEN*', 'Readme.*'
installer.install!
contents = (config.project_pods_root + 'Pods-resources.sh').read
contents.should.include "install_resource 'SSZipArchive/LICENSE'\n" \
"install_resource 'SSZipArchive/Readme.markdown'"
end
# TODO we need to do more cleaning and/or add a --prune task
it "overwrites an existing project.pbxproj file" do
spec = Pod::Podfile.new do
# first ensure that the correct info is available to the specs when they load
config.rootspec = self
self.platform platform
dependency 'JSONKit'
end
installer = SpecHelper::Installer.new(spec)
installer.install!
Pod::Source.reset!
Pod::Spec::Set.reset!
spec = Pod::Podfile.new do
# first ensure that the correct info is available to the specs when they load
config.rootspec = self
self.platform platform
dependency 'SSZipArchive'
end
installer = SpecHelper::Installer.new(spec)
installer.install!
project = Xcodeproj::Project.new(config.project_pods_root + 'Pods.xcodeproj')
project.source_files.should == installer.project.source_files
end
it "creates a project with multiple targets" do
Pod::Source.reset!
Pod::Spec::Set.reset!
podfile = Pod::Podfile.new do
# first ensure that the correct info is available to the specs when they load
config.rootspec = self
self.platform platform
target(:debug) { dependency 'SSZipArchive' }
target(:test, :exclusive => true) { dependency 'JSONKit' }
dependency 'ASIHTTPRequest'
end
installer = Pod::Installer.new(podfile)
installer.install!
#project = Pod::Xcode::Project.new(config.project_pods_root + 'Pods.xcodeproj')
#p project
#project.targets.each do |target|
#target.source_build_phases.
#end
root = config.project_pods_root
(root + 'Pods.xcconfig').should.exist
(root + 'Pods-debug.xcconfig').should.exist
(root + 'Pods-test.xcconfig').should.exist
(root + 'Pods-resources.sh').should.exist
(root + 'Pods-debug-resources.sh').should.exist
(root + 'Pods-test-resources.sh').should.exist
Dir.chdir(config.project_pods_root) do
puts "\n[!] Compiling static library `Pods'..."
should_successfully_perform "xcodebuild -target Pods"
puts "\n[!] Compiling static library `Pods-debug'..."
should_successfully_perform "xcodebuild -target Pods-debug"
puts "\n[!] Compiling static library `Pods-test'..."
should_successfully_perform "xcodebuild -target Pods-test"
end
end
it "sets up an existing project with pods" do
basename = platform == :ios ? 'iPhone' : 'Mac'
projpath = temporary_directory + 'ASIHTTPRequest.xcodeproj'
FileUtils.cp_r(fixture("integration/ASIHTTPRequest/#{basename}.xcodeproj"), projpath)
spec = Pod::Podfile.new do
self.platform platform
dependency 'SSZipArchive'
end
installer = SpecHelper::Installer.new(spec)
installer.install!
installer.configure_project(projpath)
xcworkspace = temporary_directory + 'ASIHTTPRequest.xcworkspace'
workspace = Xcodeproj::Workspace.new_from_xcworkspace(xcworkspace)
workspace.projpaths.sort.should == ['ASIHTTPRequest.xcodeproj', 'Pods/Pods.xcodeproj']
project = Xcodeproj::Project.new(projpath)
libPods = project.files.find { |f| f.name == 'libPods.a' }
project.targets.each do |target|
target.buildConfigurations.each do |config|
config.baseConfiguration.path.should == 'Pods/Pods.xcconfig'
end
phase = target.frameworks_build_phases.first
phase.files.map { |buildFile| buildFile.file }.should.include libPods
# should be the last phase
target.buildPhases.last.shellScript.should == %{"${SRCROOT}/Pods/Pods-resources.sh"\n}
end
end
end
end
end