vendor 0.0.4 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/CHANGELOG.md +22 -0
  2. data/Gemfile.lock +9 -1
  3. data/Guardfile +12 -0
  4. data/LICENSE +2 -0
  5. data/Readme.markdown +39 -23
  6. data/TODO.md +26 -0
  7. data/VERSION +1 -0
  8. data/lib/vendor.rb +6 -0
  9. data/lib/vendor/api.rb +61 -7
  10. data/lib/vendor/cli/app.rb +4 -4
  11. data/lib/vendor/cli/console.rb +7 -0
  12. data/lib/vendor/spec.rb +98 -0
  13. data/lib/vendor/templates/Vendorfile +3 -1
  14. data/lib/vendor/templates/vendorspec +15 -10
  15. data/lib/vendor/vendor_file.rb +5 -4
  16. data/lib/vendor/vendor_file/dependency_graph.rb +135 -0
  17. data/lib/vendor/vendor_file/dsl.rb +2 -0
  18. data/lib/vendor/vendor_file/library/base.rb +178 -29
  19. data/lib/vendor/vendor_file/library/git.rb +5 -1
  20. data/lib/vendor/vendor_file/library/local.rb +11 -1
  21. data/lib/vendor/vendor_file/library/remote.rb +134 -2
  22. data/lib/vendor/vendor_file/loader.rb +13 -11
  23. data/lib/vendor/vendor_spec/builder.rb +4 -7
  24. data/lib/vendor/version.rb +172 -1
  25. data/lib/vendor/xcode/project.rb +213 -4
  26. data/lib/vendor/xcode/proxy.rb +1 -0
  27. data/lib/vendor/xcode/proxy/pbx_frameworks_build_phase.rb +6 -0
  28. data/lib/vendor/xcode/proxy/pbx_reference_proxy.rb +7 -0
  29. data/lib/vendor/xcode/proxy/pbx_resources_build_phase.rb +8 -0
  30. data/lib/vendor/xcode/proxy/pbx_shell_script_build_phase.rb +8 -0
  31. data/lib/vendor/xcode/proxy/pbx_sources_build_phase.rb +6 -0
  32. data/spec/lib/vendor/api_spec.rb +54 -0
  33. data/spec/lib/vendor/spec_spec.rb +121 -0
  34. data/spec/lib/vendor/vendor_file/dependency_graph_spec.rb +129 -0
  35. data/spec/lib/vendor/vendor_file/library/base_spec.rb +174 -14
  36. data/spec/lib/vendor/vendor_file/library/remote_spec.rb +154 -4
  37. data/spec/lib/vendor/vendor_file/loader_spec.rb +4 -2
  38. data/spec/lib/vendor/vendor_spec/builder_spec.rb +2 -2
  39. data/spec/lib/vendor/version_spec.rb +168 -0
  40. data/spec/lib/vendor/xcode/project_spec.rb +175 -4
  41. data/spec/lib/vendor_spec.rb +15 -0
  42. data/spec/spec_helper.rb +3 -2
  43. data/spec/support/api_stubs.rb +57 -0
  44. data/spec/support/resources/cache/base/{DKBenchmark-Manifest → DKBenchmark-0.1-Manifest}/data/DKBenchmark.h +0 -0
  45. data/spec/support/resources/cache/base/{DKBenchmark-Manifest → DKBenchmark-0.1-Manifest}/data/DKBenchmark.m +0 -0
  46. data/spec/support/resources/cache/base/DKBenchmark-0.1-Manifest/vendor.json +1 -0
  47. data/spec/support/resources/cache/base/{DKBenchmark-Vendorspec → DKBenchmark-0.1-Nothing}/DKBenchmark.h +0 -0
  48. data/spec/support/resources/cache/base/{DKBenchmark-Vendorspec → DKBenchmark-0.1-Nothing}/DKBenchmark.m +0 -0
  49. data/spec/support/resources/cache/base/DKBenchmark-0.1-Nothing/DKBenchmark.vendorspec +16 -0
  50. data/spec/support/resources/cache/base/DKBenchmark-0.1-Vendorspec/DKBenchmark.h +18 -0
  51. data/spec/support/resources/cache/base/DKBenchmark-0.1-Vendorspec/DKBenchmark.m +73 -0
  52. data/spec/support/resources/cache/base/DKBenchmark-0.1-Vendorspec/DKBenchmark.vendorspec +24 -0
  53. data/spec/support/resources/projects/MultipleTargets/MultipleTargets.xcodeproj/project.pbxproj +624 -0
  54. data/spec/support/resources/projects/RestKitProject/RestKitProject.xcodeproj/project.pbxproj +479 -0
  55. data/spec/support/resources/projects/UtilityApplication/UtilityApplication.xcodeproj/project.pbxproj +16 -7
  56. data/spec/support/resources/vendors/DKBenchmark/DKBenchmark.vendorspec +24 -8
  57. data/spec/support/resources/vendors/DKBenchmarkUnsafe/DKBenchmark.vendorspec +17 -8
  58. data/vendor.gemspec +4 -2
  59. metadata +93 -39
  60. data/lib/vendor/vendor_spec/dsl.rb +0 -39
  61. data/lib/vendor/vendor_spec/loader.rb +0 -23
  62. data/spec/lib/vendor/vendor_spec/dsl_spec.rb +0 -67
  63. data/spec/lib/vendor/vendor_spec/loader_spec.rb +0 -41
  64. data/spec/support/resources/cache/base/DKBenchmark-Manifest/vendor.json +0 -1
  65. data/spec/support/resources/cache/base/DKBenchmark-Vendorspec/DKBenchmark.vendorspec +0 -11
@@ -2,12 +2,162 @@ require 'spec_helper'
2
2
 
3
3
  describe Vendor::VendorFile::Library::Remote do
4
4
 
5
- let(:lib) { Vendor::VendorFile::Library::Remote.new }
5
+ let(:lib) { Vendor::VendorFile::Library::Remote.new(:name => "DKBenchmark", :version => "0.1") }
6
6
 
7
- it "should have a version attribute" do
8
- lib.version = "3.0.5"
7
+ context "#download" do
8
+
9
+ before :each do
10
+ Vendor.stub(:library_path).and_return Dir.mktmpdir("spec")
11
+ end
12
+
13
+ it "should find the correct version if one isn't set on the lib" do
14
+ lib.version = nil
15
+
16
+ lib.matched_version.should == "0.2"
17
+ end
18
+
19
+ it "should download the lib if its not cached locally" do
20
+ Vendor::API.should_receive(:download).with(lib.name, lib.version).and_return(File.open(File.join(PACKAGED_VENDOR_PATH, "DKBenchmark-0.1.vendor")))
21
+
22
+ lib.download
23
+ end
24
+
25
+ it "should not download the lib if it already exists" do
26
+ File.should_receive(:exist?).with(lib.cache_path).and_return(true)
27
+ Vendor::API.should_not_receive(:download).with(lib.name, lib.version)
28
+
29
+ lib.download
30
+ end
31
+
32
+ it "should unzip the file" do
33
+ lib.download
34
+
35
+ File.exist?(File.join(lib.cache_path, "vendor.json"))
36
+ File.exist?(File.join(lib.cache_path, "data/DKBenchmark.h"))
37
+ File.exist?(File.join(lib.cache_path, "data/DKBenchmark.m"))
38
+ end
39
+
40
+ end
41
+
42
+ context "#cache_path" do
43
+
44
+ it "should contain the name of the vendor and the version" do
45
+ lib.cache_path.should =~ /DKBenchmark\/0.1$/
46
+ end
47
+
48
+ end
49
+
50
+ context "#matched_version" do
51
+
52
+ it "should just return the version if there is no equality matche" do
53
+ lib.version = "3.0.5"
54
+ lib.matched_version.should == "3.0.5"
55
+ end
56
+
57
+ it "should just return the correct version if no version is passed" do
58
+ lib.version = nil
59
+ # The DKBenchmark FakeWeb call returns 0.2 as the latest release
60
+ lib.matched_version.should == "0.2"
61
+ end
62
+
63
+ context "when finding the correct library" do
64
+
65
+ before :each do
66
+ lib.stub!('meta').and_return({ "versions" => [ [ "0.1"] , [ "0.1.1" ], [ "0.1.2.alpha" ], [ "0.2"] , [ "0.5" ], [ "0.6.1" ], [ "0.6.2" ], [ "0.6.8" ] ] })
67
+ end
68
+
69
+ it "should match <=" do
70
+ lib.version = "<= 0.5"
71
+ lib.matched_version.to_s.should == "0.6.8"
72
+ end
73
+
74
+ it "should match >=" do
75
+ lib.version = ">= 0.2"
76
+ lib.matched_version.to_s.should == "0.2"
77
+ end
78
+
79
+ it "should match >" do
80
+ lib.version = "> 0.2"
81
+ lib.matched_version.to_s.should == "0.1.1"
82
+ end
83
+
84
+ it "should match <" do
85
+ lib.version = "< 0.2"
86
+ lib.matched_version.to_s.should == "0.6.8"
87
+ end
88
+
89
+ it "should match ~>" do
90
+ lib.version = "~> 0.6"
91
+ lib.matched_version.to_s.should == "0.6.8"
92
+ end
93
+
94
+ it "should not return pre-releases" do
95
+ lib.version = "~> 0.1"
96
+ lib.matched_version.to_s.should == "0.1.1"
97
+ end
98
+
99
+ it "should return pre-releases if specified specifically" do
100
+ lib.version = "~> 0.1.2.alpha"
101
+ lib.matched_version.to_s.should == "0.1.2.alpha"
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+
108
+ context "#==" do
109
+
110
+ it "should return true if the libs match" do
111
+ x = Vendor::VendorFile::Library::Remote.new(:name => "DKRest", :version => "1.0", :equality => "~>")
112
+ y = Vendor::VendorFile::Library::Remote.new(:name => "DKRest", :version => "1.0", :equality => "~>")
113
+
114
+ x.should == y
115
+ end
116
+
117
+ it "should return false if the libs don't match" do
118
+ x = Vendor::VendorFile::Library::Remote.new(:name => "DKRest", :version => "1.0", :equality => "~>")
119
+ y = Vendor::VendorFile::Library::Remote.new(:name => "DKRest", :version => "1.1", :equality => "~>")
120
+
121
+ x.should_not == y
122
+ end
123
+
124
+ end
125
+
126
+ context "#version=" do
127
+
128
+ it "should have a version attribute" do
129
+ lib.version = "3.0.5"
130
+
131
+ lib.version.should == "3.0.5"
132
+ end
133
+
134
+ it "should handle versions with an equality matcher" do
135
+ lib.version = "<= 3.0"
136
+ lib.equality.should == "<="
137
+ lib.version.should == "3.0"
138
+
139
+ lib.version = ">= 3.1"
140
+ lib.equality.should == ">="
141
+ lib.version.should == "3.1"
142
+
143
+ lib.version = "~> 3.2"
144
+ lib.equality.should == "~>"
145
+ lib.version.should == "3.2"
146
+ end
147
+
148
+ it "should clear the version and the equality if you pass nil" do
149
+ lib.version = nil
150
+ lib.equality.should be_nil
151
+ lib.version.should be_nil
152
+ end
153
+
154
+ it "should exit if you pass something silly to it" do
155
+ expect do
156
+ Vendor.ui.should_receive(:error).with("Invalid version format '+ .5' for 'DKBenchmark'")
157
+ lib.version = "+ .5"
158
+ end.should raise_error(SystemExit)
159
+ end
9
160
 
10
- lib.version.should == "3.0.5"
11
161
  end
12
162
 
13
163
  end
@@ -39,11 +39,13 @@ describe Vendor::VendorFile::Loader do
39
39
  @libs[1].should be_kind_of(Vendor::VendorFile::Library::Remote)
40
40
 
41
41
  @libs[2].name.should == "LibWithGreaterThanVersion"
42
- @libs[2].version.should == ">=1.0"
42
+ @libs[2].version.should == "1.0"
43
+ @libs[2].equality.should == ">="
43
44
  @libs[2].should be_kind_of(Vendor::VendorFile::Library::Remote)
44
45
 
45
46
  @libs[3].name.should == "LibWithApproxVersionAndTarget"
46
- @libs[3].version.should == "~>1.0"
47
+ @libs[3].version.should == "1.0"
48
+ @libs[3].equality.should == "~>"
47
49
  @libs[3].targets.should == [ "something" ]
48
50
  @libs[3].should be_kind_of(Vendor::VendorFile::Library::Remote)
49
51
  end
@@ -9,7 +9,7 @@ describe Vendor::VendorSpec::Builder do
9
9
  let (:builder) { Vendor::VendorSpec::Builder.new(File.join(VENDOR_RESOURCE_PATH, "DKBenchmark", "DKBenchmark.vendorspec")) }
10
10
 
11
11
  it "should load in the vendor spec" do
12
- builder.vendor_spec[:name].should == "DKBenchmark"
12
+ builder.vendor_spec.name.should == "DKBenchmark"
13
13
  end
14
14
 
15
15
  it "should load the name of the vendor" do
@@ -31,7 +31,7 @@ describe Vendor::VendorSpec::Builder do
31
31
  let (:builder) { Vendor::VendorSpec::Builder.new(File.join(VENDOR_RESOURCE_PATH, "DKBenchmarkUnsafe", "DKBenchmark.vendorspec")) }
32
32
 
33
33
  it "should load in the vendor spec" do
34
- builder.vendor_spec[:name].should == "DKBen!/asdf535chmark"
34
+ builder.vendor_spec.name.should == "DKBen!/asdf535chmark"
35
35
  end
36
36
 
37
37
  it "should load the name of the vendor" do
@@ -0,0 +1,168 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vendor::Version do
4
+
5
+ describe "#bump" do
6
+
7
+ it "should incement versions" do
8
+ v("5.2.4").bump.should == v("5.3")
9
+ end
10
+
11
+ it "should bump from an alpha" do
12
+ v("5.2.4.a").bump.should == v("5.3")
13
+ end
14
+
15
+ it "should bump from an alpha numberic extension" do
16
+ v("5.2.4.a10").bump.should == v("5.3")
17
+ end
18
+
19
+ it "should bump with trailing zeros" do
20
+ v("5.0.0").bump.should == v("5.1")
21
+ end
22
+
23
+ it "should bump from one level" do
24
+ v("5").bump.should == v("6")
25
+ end
26
+
27
+ end
28
+
29
+ describe "#create" do
30
+
31
+ it "should return itself when passing in a version object" do
32
+ Vendor::Version.create(v("1.0")).should == v("1.0")
33
+ end
34
+
35
+ it "should return nil when passing nil" do
36
+ Vendor::Version.create(nil).should be_nil
37
+ end
38
+
39
+ it "should allow you to create a version from a string" do
40
+ Vendor::Version.create("5.1").should == v("5.1")
41
+ end
42
+
43
+ end
44
+
45
+ describe "#==" do
46
+
47
+ it "should equal versions if the versions are the same" do
48
+ v("1.2").should == v("1.2")
49
+ v("1.2.b1").should == v("1.2.b.1")
50
+ end
51
+
52
+ it "should not equal if the versions are different" do
53
+ v("1.2").should_not == v("1.2.3")
54
+ end
55
+
56
+ end
57
+
58
+ describe "#eql?" do
59
+
60
+ it "should equal versions if the versions are the same" do
61
+ v("1.2").should == v("1.2")
62
+ end
63
+
64
+ it "should not equal if the versions are different" do
65
+ v("1.2").eql?(v("1.2.3")).should be_false
66
+ v("1.2.0").eql?(v("1.2")).should be_false
67
+ v("1.2.b1").eql?(v("1.2.b.1")).should be_false
68
+ end
69
+
70
+ end
71
+
72
+ describe "#initialize" do
73
+
74
+ ["1.0", "1.0 ", " 1.0 ", "1.0\n", "\n1.0\n"].each do |good|
75
+ it "should handle different input formats (#{good.inspect})" do
76
+ Vendor::Version.new(good).should == v("1.0")
77
+ end
78
+ end
79
+
80
+ it "should handle integers" do
81
+ Vendor::Version.new("1").should == v(1)
82
+ end
83
+
84
+ ["junk", "1.0\n2.0"].each do |bad|
85
+ it "should raise argument errors for bad version formats (#{bad.inspect})" do
86
+
87
+ expect do
88
+ Vendor::Version.new(bad)
89
+ end.should raise_error(ArgumentError, "Malformed version number string #{bad}")
90
+
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ describe "#prerelease" do
97
+
98
+ it "should return true if the version is a prerelease" do
99
+ v("1.2.0.a").should be_prerelease
100
+ v("2.9.b").should be_prerelease
101
+ v("22.1.50.0.d").should be_prerelease
102
+ v("1.2.d.42").should be_prerelease
103
+ v('1.A').should be_prerelease
104
+ end
105
+
106
+ it "should return false if the version is not a prerelease" do
107
+ v("1.2.0").should_not be_prerelease
108
+ v("2.9").should_not be_prerelease
109
+ v("22.1.50.0").should_not be_prerelease
110
+ end
111
+
112
+ end
113
+
114
+ describe "#release" do
115
+
116
+ it "should return the release version" do
117
+ v("1.2.0.a").release.should == v("1.2.0")
118
+ v("1.1.rc10").release.should == v("1.1")
119
+ v("1.9.3.alpha.5").release.should == v("1.9.3")
120
+ v("1.9.3").release.should == v("1.9.3")
121
+ end
122
+
123
+ end
124
+
125
+ describe "<=>" do
126
+
127
+ it "should return the correct value from the spaceship operator" do
128
+ (v("1.0") <=> v("1.0.0")).should == 0
129
+ (v("1.0") <=> v("1.0.a")).should == 1
130
+ (v("1.8.2") <=> v("0.0.0")).should == 1
131
+ (v("1.8.2") <=> v("1.8.2.a")).should == 1
132
+ (v("1.8.2.b") <=> v("1.8.2.a")).should == 1
133
+ (v("1.8.2.a") <=> v("1.8.2")).should == -1
134
+ (v("1.8.2.a10") <=> v("1.8.2.a9")).should == 1
135
+ (v("") <=> v("0")).should == 0
136
+
137
+ end
138
+
139
+ end
140
+
141
+ describe "#spermy_recommendation" do
142
+
143
+ it "should return the correct recomendation" do
144
+ v("1").spermy_recommendation.should == "~> 1.0"
145
+ v("1.0").spermy_recommendation.should == "~> 1.0"
146
+ v("1.2").spermy_recommendation.should == "~> 1.2"
147
+ v("1.2.0").spermy_recommendation.should == "~> 1.2"
148
+ v("1.2.3").spermy_recommendation.should == "~> 1.2"
149
+ v("1.2.3.a.4").spermy_recommendation.should == "~> 1.2"
150
+ end
151
+
152
+ end
153
+
154
+ describe "#to_s" do
155
+
156
+ it "should return a string represenation of the version" do
157
+ v("5.2.4").to_s.should == "5.2.4"
158
+ end
159
+
160
+ end
161
+
162
+ private
163
+
164
+ def v(version)
165
+ Vendor::Version.create(version)
166
+ end
167
+
168
+ end
@@ -42,6 +42,16 @@ describe Vendor::XCode::Project do
42
42
 
43
43
  end
44
44
 
45
+ context "RestKitProject.xcodeproj" do
46
+
47
+ it "should parse and load all the objects" do
48
+ project = Vendor::XCode::Project.new(File.join(PROJECT_RESOURCE_PATH, "RestKitProject/RestKitProject.xcodeproj"))
49
+
50
+ project.objects.length.should == 69
51
+ end
52
+
53
+ end
54
+
45
55
  end
46
56
 
47
57
  context "#name" do
@@ -188,7 +198,18 @@ describe Vendor::XCode::Project do
188
198
  File.exist?(file).should be_false
189
199
  end
190
200
 
191
- it "should remove the files from the build targets"
201
+ it "should remove the files from all the targets" do
202
+ ids = @temp_project.find_group("UtilityApplication/Classes").children.map(&:id)
203
+ @temp_project.remove_group("UtilityApplication/Classes")
204
+
205
+ @temp_project.root_object.targets.each do |target|
206
+ ids.each do |id|
207
+ target.build_phases.each do |phase|
208
+ phase.files.map(&:file_ref).map(&:id).should_not include(id)
209
+ end
210
+ end
211
+ end
212
+ end
192
213
 
193
214
  private
194
215
 
@@ -210,7 +231,85 @@ describe Vendor::XCode::Project do
210
231
 
211
232
  end
212
233
 
213
- context "#remove_file"
234
+ context "#add_framework" do
235
+
236
+ before :each do
237
+ @temp_path = TempProject.create(File.join(PROJECT_RESOURCE_PATH, "MultipleTargets"))
238
+ @temp_project = Vendor::XCode::Project.new(File.join(@temp_path, "MultipleTargets.xcodeproj"))
239
+ end
240
+
241
+ it "should add the framework to the right targets" do
242
+ @temp_project.should_receive(:add_file).with({ :targets => @temp_project.find_target("Integration"),
243
+ :file => "System/Library/Frameworks/KeithPitt.framework",
244
+ :path => "Frameworks",
245
+ :source_tree => :sdkroot })
246
+
247
+ @temp_project.add_framework "KeithPitt.framework", :targets => "Integration"
248
+ end
249
+
250
+ it "shouldn't add the framework if it already exists" do
251
+ @temp_project.should_not_receive(:add_file)
252
+
253
+ @temp_project.add_framework "Foundation.framework", :targets => "Integration"
254
+ end
255
+
256
+ end
257
+
258
+ context "#add_build_setting" do
259
+
260
+ before :each do
261
+ @temp_path = TempProject.create(File.join(PROJECT_RESOURCE_PATH, "MultipleTargets"))
262
+ @temp_project = Vendor::XCode::Project.new(File.join(@temp_path, "MultipleTargets.xcodeproj"))
263
+ @target = @temp_project.find_target("Specs")
264
+ end
265
+
266
+ it "should add build settings if they are not there" do
267
+ @temp_project.add_build_setting "SOMETHING", "YES", :targets => "Specs", :changer => "SomeLib"
268
+
269
+ @target.build_configuration_list.build_configurations.each do |config|
270
+ config.build_settings.keys.should include("SOMETHING")
271
+ config.build_settings["SOMETHING"].should == "YES"
272
+ end
273
+ end
274
+
275
+ it "should create an array of options if the setting is known to be a selection" do
276
+ @temp_project.add_build_setting "OTHER_LDFLAGS", "-ObjC", :targets => "Specs", :changer => "SomeLib"
277
+ @temp_project.add_build_setting "OTHER_LDFLAGS", "-Something", :targets => "Specs", :changer => "SomeLib"
278
+
279
+ @target.build_configuration_list.build_configurations.each do |config|
280
+ config.build_settings["OTHER_LDFLAGS"].should == [ "-ObjC", "-Something" ]
281
+ end
282
+ end
283
+
284
+ it "should not duplicate build settings" do
285
+ @temp_project.add_build_setting "OTHER_LDFLAGS", "-ObjC", :targets => "Specs", :changer => "SomeLib"
286
+ @temp_project.add_build_setting "OTHER_LDFLAGS", "-ObjC", :targets => "Specs", :changer => "SomeLib"
287
+
288
+ @target.build_configuration_list.build_configurations.each do |config|
289
+ config.build_settings["OTHER_LDFLAGS"].should == "-ObjC"
290
+ end
291
+ end
292
+
293
+ it "shouldn't change a build setting if it already exists" do
294
+ @temp_project.add_build_setting "SOMETHING", "YES", :targets => "Specs", :changer => "SomeLib"
295
+
296
+ Vendor.ui.should_receive(:warn).with(" Build setting \"SOMETHING\" wanted to change to \"NO\", but it was already \"YES\" in \"Specs/Debug\"").ordered
297
+ Vendor.ui.should_receive(:warn).with(" Build setting \"SOMETHING\" wanted to change to \"NO\", but it was already \"YES\" in \"Specs/Release\"").ordered
298
+ @temp_project.add_build_setting "SOMETHING", "NO", :targets => "Specs", :changer => "SomeLib"
299
+
300
+ @target.build_configuration_list.build_configurations.each do |config|
301
+ config.build_settings.keys.should include("SOMETHING")
302
+ config.build_settings["SOMETHING"].should == "YES"
303
+ end
304
+ end
305
+
306
+ it "should mark the project as dirty" do
307
+ @temp_project.add_build_setting "SOMETHING", "YES", :targets => "Specs", :changer => "SomeLib"
308
+
309
+ @temp_project.dirty?.should be_true
310
+ end
311
+
312
+ end
214
313
 
215
314
  context '#add_file' do
216
315
 
@@ -280,7 +379,72 @@ describe Vendor::XCode::Project do
280
379
  @temp_project.save
281
380
  end
282
381
 
283
- it 'should add it to the build targets specified'
382
+ it 'should add it to the build targets specified' do
383
+ build_phase = @target.build_phases.first
384
+
385
+ build_phase.files[-2].file_ref.should_not == @first_file_added
386
+
387
+ build_phase.files[-1].isa.should == "PBXBuildFile"
388
+ build_phase.files[-1].should be_kind_of(Vendor::XCode::Proxy::PBXBuildFile)
389
+ build_phase.files[-1].file_ref.should == @second_file_added
390
+ end
391
+
392
+ it "should throw an error if you try and add to a target that doesn't exist" do
393
+ expect do
394
+ @temp_project.add_file :targets => [ "Blah" ], :file => first_file,
395
+ :path => "Controllers/SecondViewController", :source_tree => :group
396
+ end.should raise_error(StandardError, "Could not find target 'Blah' in project 'ProjectWithSpecs'")
397
+ end
398
+
399
+ end
400
+
401
+ context "with a source tree of :sdkroot" do
402
+
403
+ before :each do
404
+ @first_file_added = @temp_project.add_file :targets => [ @target ], :file => "System/Library/Frameworks/Foundation.framework",
405
+ :path => "Frameworks", :source_tree => :sdkroot
406
+ @second_file_added = @temp_project.add_file :targets => [ @target ], :file => "System/Library/Frameworks/CoreGraphics.framework",
407
+ :path => "Frameworks", :source_tree => :sdkroot
408
+ end
409
+
410
+ it "should mark the project as dirty" do
411
+ @temp_project.dirty.should be_true
412
+ end
413
+
414
+ it 'should add it as the correct file type' do
415
+ @first_file_added.last_known_file_type.should == "wrapper.framework"
416
+ @second_file_added.last_known_file_type.should == "wrapper.framework"
417
+ end
418
+
419
+ it 'should add the files with the correct path' do
420
+ @first_file_added.path.should == "System/Library/Frameworks/Foundation.framework"
421
+ @second_file_added.path.should == "System/Library/Frameworks/CoreGraphics.framework"
422
+ end
423
+
424
+ it 'should have an ID' do
425
+ @first_file_added.id.should_not be_nil
426
+ @second_file_added.id.should_not be_nil
427
+ end
428
+
429
+ it 'should add it to the correct group' do
430
+ group = @temp_project.create_group("Frameworks")
431
+
432
+ group.children[-2].should == @first_file_added
433
+ group.children[-1].should == @second_file_added
434
+ end
435
+
436
+ it 'should still save' do
437
+ @temp_project.save
438
+ end
439
+
440
+ it 'should add it to the build targets specified' do
441
+ build_phase = @target.build_phases[1]
442
+
443
+ build_phase.files[-2].should be_kind_of(Vendor::XCode::Proxy::PBXBuildFile)
444
+ build_phase.files[-2].file_ref.should == @first_file_added
445
+ build_phase.files[-1].should be_kind_of(Vendor::XCode::Proxy::PBXBuildFile)
446
+ build_phase.files[-1].file_ref.should == @second_file_added
447
+ end
284
448
 
285
449
  end
286
450
 
@@ -334,7 +498,14 @@ describe Vendor::XCode::Project do
334
498
  @temp_project.save
335
499
  end
336
500
 
337
- it 'should add it to the build targets specified'
501
+ it 'should add it to the build targets specified' do
502
+ build_phase = @target.build_phases.first
503
+
504
+ build_phase.files[-2].file_ref.should_not == @first_file_added
505
+
506
+ build_phase.files[-1].should be_kind_of(Vendor::XCode::Proxy::PBXBuildFile)
507
+ build_phase.files[-1].file_ref.should == @second_file_added
508
+ end
338
509
 
339
510
  end
340
511