vendor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +12 -0
  2. data/.travis.yml +4 -0
  3. data/Gemfile +8 -0
  4. data/Gemfile.lock +68 -0
  5. data/LICENCE +19 -0
  6. data/Rakefile +11 -0
  7. data/Readme.markdown +109 -0
  8. data/bin/vendor +62 -0
  9. data/lib/vendor/api.rb +49 -0
  10. data/lib/vendor/cli/auth.rb +38 -0
  11. data/lib/vendor/cli.rb +23 -0
  12. data/lib/vendor/config.rb +51 -0
  13. data/lib/vendor/extensions/array.rb +7 -0
  14. data/lib/vendor/extensions/fixnum.rb +7 -0
  15. data/lib/vendor/extensions/hash.rb +10 -0
  16. data/lib/vendor/extensions/string.rb +11 -0
  17. data/lib/vendor/plist.rb +255 -0
  18. data/lib/vendor/vendor_spec/builder.rb +83 -0
  19. data/lib/vendor/vendor_spec/dsl.rb +39 -0
  20. data/lib/vendor/vendor_spec/loader.rb +23 -0
  21. data/lib/vendor/version.rb +5 -0
  22. data/lib/vendor/xcode/object.rb +102 -0
  23. data/lib/vendor/xcode/objects/pbx_build_file.rb +9 -0
  24. data/lib/vendor/xcode/objects/pbx_container_item_proxy.rb +8 -0
  25. data/lib/vendor/xcode/objects/pbx_file_reference.rb +21 -0
  26. data/lib/vendor/xcode/objects/pbx_frameworks_build_phase.rb +9 -0
  27. data/lib/vendor/xcode/objects/pbx_group.rb +13 -0
  28. data/lib/vendor/xcode/objects/pbx_native_target.rb +11 -0
  29. data/lib/vendor/xcode/objects/pbx_project.rb +12 -0
  30. data/lib/vendor/xcode/objects/pbx_resources_build_phase.rb +7 -0
  31. data/lib/vendor/xcode/objects/pbx_shell_script_build_phase.rb +7 -0
  32. data/lib/vendor/xcode/objects/pbx_sources_build_phase.rb +9 -0
  33. data/lib/vendor/xcode/objects/pbx_target_dependency.rb +7 -0
  34. data/lib/vendor/xcode/objects/pbx_variant_group.rb +7 -0
  35. data/lib/vendor/xcode/objects/xc_build_configuration.rb +7 -0
  36. data/lib/vendor/xcode/objects/xc_configuration_list.rb +9 -0
  37. data/lib/vendor/xcode/project.rb +130 -0
  38. data/lib/vendor.rb +33 -0
  39. data/spec/spec_helper.rb +17 -0
  40. data/spec/support/api_stubs.rb +12 -0
  41. data/spec/support/resources/files/SecondViewController.h +13 -0
  42. data/spec/support/resources/files/SecondViewController.m +43 -0
  43. data/spec/support/resources/projects/ProjectWithSpecs/ProjectWithSpecs.xcodeproj/project.pbxproj +320 -0
  44. data/spec/support/resources/projects/TabBarWithUnitTests/TabBarWithUnitTests.xcodeproj/project.pbxproj +473 -0
  45. data/spec/support/resources/vendors/DKBenchmark/DKBenchmark.h +18 -0
  46. data/spec/support/resources/vendors/DKBenchmark/DKBenchmark.m +73 -0
  47. data/spec/support/resources/vendors/DKBenchmark/DKBenchmark.vendorspec +11 -0
  48. data/spec/support/resources/vendors/DKBenchmarkUnsafe/DKBenchmark.h +18 -0
  49. data/spec/support/resources/vendors/DKBenchmarkUnsafe/DKBenchmark.m +73 -0
  50. data/spec/support/resources/vendors/DKBenchmarkUnsafe/DKBenchmark.vendorspec +11 -0
  51. data/spec/support/temp_project.rb +21 -0
  52. data/spec/vendor/api_spec.rb +25 -0
  53. data/spec/vendor/cli/auth_spec.rb +54 -0
  54. data/spec/vendor/config_spec.rb +62 -0
  55. data/spec/vendor/vendor_spec/builder_spec.rb +86 -0
  56. data/spec/vendor/vendor_spec/dsl_spec.rb +67 -0
  57. data/spec/vendor/vendor_spec/loader_spec.rb +41 -0
  58. data/spec/vendor/xcode/object_spec.rb +76 -0
  59. data/spec/vendor/xcode/objects/pbx_project_spec.rb +26 -0
  60. data/spec/vendor/xcode/project_spec.rb +211 -0
  61. data/vendor.gemspec +33 -0
  62. metadata +234 -0
@@ -0,0 +1,21 @@
1
+ module TempProject
2
+
3
+ require 'fileutils'
4
+
5
+ def self.cleanup
6
+ FileUtils.rm_rf TEMP_PROJECT_PATH
7
+ FileUtils.mkdir TEMP_PROJECT_PATH
8
+ end
9
+
10
+ def self.create(project_path)
11
+ name = File.basename(project_path)
12
+ location = File.join(TEMP_PROJECT_PATH, name)
13
+
14
+ FileUtils.rm_rf location if File.exists?(location)
15
+
16
+ FileUtils.cp_r project_path, TEMP_PROJECT_PATH
17
+
18
+ location
19
+ end
20
+
21
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vendor::API do
4
+
5
+ context "#api_key" do
6
+
7
+ it "should raise an error if the server returns a 401" do
8
+ expect do
9
+ Vendor::API.api_key("keithpitt", "wrong")
10
+ end.should raise_error(Vendor::API::Error, "Login or password is incorrect")
11
+ end
12
+
13
+ it "should raise an error if the server returns a non 200" do
14
+ expect do
15
+ Vendor::API.api_key("keithpitt", "error")
16
+ end.should raise_error(Vendor::API::Error, "Could not complete request. Server returned a status code of 500")
17
+ end
18
+
19
+ it "should return an API key if the server returns a 200" do
20
+ Vendor::API.api_key("keithpitt", "password").should == "secret"
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vendor::CLI::Auth do
4
+
5
+ context "#is_authenticated?" do
6
+
7
+ it "should return false if no api key is set" do
8
+ Vendor::CLI::Auth.api_key = nil
9
+
10
+ Vendor::CLI::Auth.is_authenticated?.should be_false
11
+ end
12
+
13
+ it "should return true if an api key is set" do
14
+ Vendor::CLI::Auth.api_key = "secret"
15
+
16
+ Vendor::CLI::Auth.is_authenticated?.should be_true
17
+ end
18
+
19
+ end
20
+
21
+ context "#with_api_key" do
22
+
23
+ it "should ask for credentials credentials before running the block if they're not authenticated" do
24
+ Vendor::CLI::Auth.api_key = nil
25
+ Vendor::CLI::Auth.should_receive :fetch_api_key
26
+
27
+ Vendor::CLI::Auth.with_api_key { |api_key| }
28
+ end
29
+
30
+ it "should run the block with the API key if one exists" do
31
+ Vendor::CLI::Auth.api_key = "secret"
32
+ Vendor::CLI::Auth.should_not_receive :fetch_api_key
33
+
34
+ Vendor::CLI::Auth.with_api_key do |api_key|
35
+ api_key.should == "secret"
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ context "#fetch_api_key" do
42
+
43
+ it "should ask for their username and password" do
44
+ STDIN.should_receive(:gets).once.ordered.and_return "keithpitt"
45
+ STDIN.should_receive(:gets).once.ordered.and_return "password"
46
+ Vendor::CLI::Auth.should_receive(:puts).once
47
+ Vendor::CLI::Auth.should_receive(:printf).twice
48
+
49
+ Vendor::CLI::Auth.fetch_api_key.should == "secret"
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vendor::Config do
4
+
5
+ context "#directory" do
6
+
7
+ it "should return the development directory" do
8
+ Vendor::Config.directory.should == File.expand_path(File.join(__FILE__, "..", "..", "..", "tmp", "config"))
9
+ end
10
+
11
+ end
12
+
13
+ context "#directory=" do
14
+
15
+ it "should allow you to set a new directory" do
16
+ old_directory = Vendor::Config.directory
17
+
18
+ Vendor::Config.directory = "something"
19
+ Vendor::Config.directory.should == "something"
20
+
21
+ Vendor::Config.directory = old_directory
22
+ end
23
+
24
+ end
25
+
26
+ context "#set" do
27
+
28
+ it "should create a file if one doesn't exist" do
29
+ Vendor::Config.set "some.config", "a value"
30
+
31
+ File.exist?(File.join(Vendor::Config.directory, "config")).should be_true
32
+ end
33
+
34
+ it "should allow you to set configs" do
35
+ Vendor::Config.set "config", "a value"
36
+
37
+ Vendor::Config.get("config").should == "a value"
38
+ end
39
+
40
+ it "should allow you to set configs at multiple levels" do
41
+ Vendor::Config.set "config.at.some.crazy.level", "a value"
42
+
43
+ Vendor::Config.get("config.at.some.crazy.level").should == "a value"
44
+ end
45
+
46
+ it "should allow you to set symbols" do
47
+ Vendor::Config.set :"config.at.some.crazy.level", "a value"
48
+
49
+ Vendor::Config.get("config.at.some.crazy.level").should == "a value"
50
+ end
51
+
52
+ end
53
+
54
+ context "#get" do
55
+
56
+ it "should return nil if the config doesn't exist" do
57
+ Vendor::Config.get("this.dont.exist").should be_nil
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vendor::VendorSpec::Builder do
4
+
5
+ context "#initialize" do
6
+
7
+ context "with a valid vendor spec" do
8
+
9
+ let (:builder) { Vendor::VendorSpec::Builder.new(File.join(VENDOR_RESOURCE_PATH, "DKBenchmark", "DKBenchmark.vendorspec")) }
10
+
11
+ it "should load in the vendor spec" do
12
+ builder.vendor_spec[:name].should == "DKBenchmark"
13
+ end
14
+
15
+ it "should load the name of the vendor" do
16
+ builder.name.should == "DKBenchmark"
17
+ end
18
+
19
+ it "should the version of the vendor" do
20
+ builder.version.should == "0.1"
21
+ end
22
+
23
+ it "should create a filename for the vendor" do
24
+ builder.filename.should == "DKBenchmark-0.1.vendor"
25
+ end
26
+
27
+ end
28
+
29
+ context "with an invalid vendor spec" do
30
+
31
+ let (:builder) { Vendor::VendorSpec::Builder.new(File.join(VENDOR_RESOURCE_PATH, "DKBenchmarkUnsafe", "DKBenchmark.vendorspec")) }
32
+
33
+ it "should load in the vendor spec" do
34
+ builder.vendor_spec[:name].should == "DKBen!/asdf535chmark"
35
+ end
36
+
37
+ it "should load the name of the vendor" do
38
+ builder.name.should == "DKBenasdf535chmark"
39
+ end
40
+
41
+ it "should the version of the vendor" do
42
+ builder.version.should == "0.1asdf52fs"
43
+ end
44
+
45
+ it "should create a filename for the vendor" do
46
+ builder.filename.should == "DKBenasdf535chmark-0.1asdf52fs.vendor"
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ context "#build" do
54
+
55
+ let (:builder) { Vendor::VendorSpec::Builder.new(File.join(VENDOR_RESOURCE_PATH, "DKBenchmark", "DKBenchmark.vendorspec")) }
56
+
57
+ before :all do
58
+ builder.build
59
+ end
60
+
61
+ it "should create the .vendor file" do
62
+ File.exist?(builder.filename).should be_true
63
+ end
64
+
65
+ it "should be a zip file" do
66
+ mimetype = `file #{builder.filename} --mime-type`.chomp
67
+
68
+ mimetype.should =~ /application\/zip/
69
+ end
70
+
71
+ it "should contain a vendor.json file" do
72
+ Zip::ZipFile.open(builder.filename) do |zipfile|
73
+ zipfile.file.read("vendor.json").should == builder.vendor_spec.to_json
74
+ end
75
+ end
76
+
77
+ it "should contain the files contained in the vendor spec" do
78
+ Zip::ZipFile.open(builder.filename) do |zipfile|
79
+ zipfile.file.read("data/DKBenchmark.h") =~ /DKBenchmark\.h/
80
+ zipfile.file.read("data/DKBenchmark.m") =~ /DKBenchmark\.m/
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vendor::VendorSpec::DSL do
4
+
5
+ let! (:dsl) { Vendor::VendorSpec::DSL.new }
6
+
7
+ context '#vendor_spec' do
8
+
9
+ it 'should load all the properties into the vendor spec' do
10
+ dsl.foo "foo"
11
+ dsl.cheese "is good"
12
+
13
+ dsl.vendor_spec.should == { :foo => "foo", :cheese => "is good" }
14
+ end
15
+
16
+ end
17
+
18
+ context '#validate' do
19
+
20
+ before :each do
21
+ dsl.name = "Vendor"
22
+ dsl.files = "Something"
23
+ dsl.email = "foo@bar.com"
24
+ dsl.version = "0.1"
25
+ end
26
+
27
+ it 'should thorw an error if no name is defined' do
28
+ expect do
29
+ dsl.name = nil
30
+ dsl.validate!
31
+ end.should raise_error("Specification is missing the `name` option")
32
+ end
33
+
34
+ it 'should thorw an error if no email is defined' do
35
+ expect do
36
+ dsl.email = nil
37
+ dsl.validate!
38
+ end.should raise_error("Specification is missing the `email` option")
39
+ end
40
+
41
+ it 'should thorw an error if no version is defined' do
42
+ expect do
43
+ dsl.version = nil
44
+ dsl.validate!
45
+ end.should raise_error("Specification is missing the `version` option")
46
+ end
47
+
48
+ it 'should thorw an error if no files are defined' do
49
+ expect do
50
+ dsl.files = nil
51
+ dsl.validate!
52
+ end.should raise_error("Specification is missing the `files` option")
53
+ end
54
+
55
+ end
56
+
57
+ context '#to_json' do
58
+
59
+ it 'should return the vendor spec as a JSON string' do
60
+ dsl.foo "foo"
61
+
62
+ dsl.to_json.should == dsl.vendor_spec.to_json
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vendor::VendorSpec::Loader do
4
+
5
+ let (:loader) { Vendor::VendorSpec::Loader.new }
6
+
7
+ context "#initialize" do
8
+
9
+ it "should create a dsl" do
10
+ loader.dsl.should be_kind_of?(Vendor::VendorSpec::DSL)
11
+ end
12
+
13
+ end
14
+
15
+ context "#vendor" do
16
+
17
+ it "should allow you to pass a block and define vendor spec properties" do
18
+ loader.vendor do
19
+ name "Something"
20
+ files [ "Foo", "Bar" ]
21
+ end
22
+
23
+ loader.dsl.name.should == "Something"
24
+ loader.dsl.files.should == [ "Foo", "Bar" ]
25
+ end
26
+
27
+ end
28
+
29
+ context "#load" do
30
+
31
+ it "should allow you to load from a file" do
32
+ loader.load File.join(VENDOR_RESOURCE_PATH, "DKBenchmark", "DKBenchmark.vendorspec")
33
+
34
+ loader.dsl.name.should == "DKBenchmark"
35
+ loader.dsl.authors.should == "keithpitt"
36
+ loader.dsl.email.should == "me@keithpitt.com"
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vendor::XCode::Object do
4
+
5
+ before :all do
6
+ @project = Vendor::XCode::Project.new(File.join(PROJECT_RESOURCE_PATH, "ProjectWithSpecs/ProjectWithSpecs.xcodeproj"))
7
+ @pbx_project = @project.root_object
8
+ end
9
+
10
+ context "#inspect" do
11
+
12
+ it "should give you the attributes in the object" do
13
+ @pbx_project.build_configuration_list.inspect.should include("Vendor::XCode::Objects::XCConfigurationList")
14
+ @pbx_project.build_configuration_list.inspect.should include("id: \"53787482140109AE00D9B746\"")
15
+ @pbx_project.build_configuration_list.inspect.should include("build_configurations: [\"53787484140109AE00D9B746\", \"53787485140109AE00D9B746\"]")
16
+ @pbx_project.build_configuration_list.inspect.should include("default_configuration_is_visible: \"0\"")
17
+ @pbx_project.build_configuration_list.inspect.should include("default_configuration_name: \"Release\"")
18
+ end
19
+
20
+ end
21
+
22
+ context "#attribute_name"do
23
+
24
+ it "should convert the attribute to the correct format used in the project file (camel case)" do
25
+ Vendor::XCode::Object.attribute_name('build_config_list').should == "buildConfigList"
26
+ end
27
+
28
+ end
29
+
30
+ context "#method_missing" do
31
+
32
+ it "should allow you to access attributes using an underscore case" do
33
+ @pbx_project.known_regions.should == [ "en" ]
34
+ end
35
+
36
+ it "should allow you to set attributes using an underscore case" do
37
+ @pbx_project.known_regions = [ "fn" ]
38
+
39
+ @pbx_project.known_regions.should == [ "fn" ]
40
+ end
41
+
42
+ end
43
+
44
+ context "#write_attribute" do
45
+
46
+ it "should allow you to set existing attributes" do
47
+ @pbx_project.write_attribute('knownRegions', [ "en" ])
48
+ end
49
+
50
+ it "should allow symbols to be passed" do
51
+ @pbx_project.write_attribute(:knownRegions, [ "en" ])
52
+ end
53
+
54
+ after :each do
55
+ @pbx_project.known_regions.should == [ "en" ]
56
+ end
57
+
58
+ end
59
+
60
+ context "#read_attribute" do
61
+
62
+ before :each do
63
+ @pbx_project.known_regions = [ 'uk' ]
64
+ end
65
+
66
+ it "should allow you to read an attribute" do
67
+ @pbx_project.read_attribute('knownRegions').should == [ 'uk' ]
68
+ end
69
+
70
+ it 'should allow symbols to be used' do
71
+ @pbx_project.read_attribute(:knownRegions).should == [ 'uk' ]
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vendor::XCode::Project do
4
+
5
+ before :all do
6
+ @project = Vendor::XCode::Project.new(File.join(PROJECT_RESOURCE_PATH, "ProjectWithSpecs/ProjectWithSpecs.xcodeproj"))
7
+ @pbx_project = @project.root_object
8
+ end
9
+
10
+ it "should reference the build configuration list" do
11
+ @pbx_project.build_configuration_list.should == @project.find_object('53787482140109AE00D9B746')
12
+ end
13
+
14
+ it "should reference the product reference group" do
15
+ @pbx_project.product_ref_group.should == @project.find_object('537874A014010A0A00D9B746')
16
+ end
17
+
18
+ it "should reference the main group" do
19
+ @pbx_project.main_group.should == @project.find_object('5378747D140109AE00D9B746')
20
+ end
21
+
22
+ it "should reference the targets" do
23
+ @pbx_project.targets.should == [ @project.find_object("5378749E14010A0A00D9B746") ]
24
+ end
25
+
26
+ end
@@ -0,0 +1,211 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vendor::XCode::Project do
4
+
5
+ before :each do
6
+ @project = Vendor::XCode::Project.new(File.join(PROJECT_RESOURCE_PATH, "ProjectWithSpecs/ProjectWithSpecs.xcodeproj"))
7
+ end
8
+
9
+ context "#initialize" do
10
+
11
+ context "ProjectWithSpecs.xcodeproj" do
12
+
13
+ it "should load all the objects" do
14
+ @project.objects.length.should == 48
15
+ end
16
+
17
+ it "should load the object version" do
18
+ @project.object_version.should == 46
19
+ end
20
+
21
+ it "should load the archive version" do
22
+ @project.archive_version.should == 1
23
+ end
24
+
25
+ it "should populate the root object" do
26
+ @project.root_object.should_not be_nil
27
+ end
28
+
29
+ end
30
+
31
+ context "TabBarWithUnitTests.xcodeproj" do
32
+
33
+ it "should parse and load all the objects" do
34
+ project = Vendor::XCode::Project.new(File.join(PROJECT_RESOURCE_PATH, "TabBarWithUnitTests/TabBarWithUnitTests.xcodeproj"))
35
+
36
+ project.objects.length.should == 74
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ context "#find_object" do
44
+
45
+ it "should return the object mapped to the id" do
46
+ @project.find_object('5378747F140109AE00D9B746').should == @project.root_object
47
+ end
48
+
49
+ end
50
+
51
+ context "#find_target" do
52
+
53
+ it "should return the target" do
54
+ @project.find_target('Specs').should == @project.root_object.targets.first
55
+ end
56
+
57
+ it "should return nil if one cannot be found" do
58
+ @project.find_target('Ruut').should be_nil
59
+ end
60
+
61
+ end
62
+
63
+ context '#find_and_make_group' do
64
+
65
+ context 'when finding an existing group' do
66
+
67
+ it "should return the group" do
68
+ @project.find_and_make_group("Specs/Supporting Files").should == @project.root_object.main_group.children.first.children.first
69
+ end
70
+
71
+ end
72
+
73
+ context 'when creating a group' do
74
+
75
+ before :each do
76
+ @group = @project.find_and_make_group("Specs/Supporting Files/Something/Goes Inside/Here")
77
+
78
+ @supporting_files_group = @project.root_object.main_group.children.first.children.first
79
+ @something_group = @supporting_files_group.children.last
80
+ @inside_group = @something_group.children.last
81
+ @here_group = @inside_group.children.last
82
+ end
83
+
84
+ it 'should create it in the correct location' do
85
+ @here_group.should_not be_nil
86
+ end
87
+
88
+ it 'should give the new groups the right names' do
89
+ @something_group.name.should == "Something"
90
+ @inside_group.name.should == "Goes Inside"
91
+ @here_group.name.should == "Here"
92
+ end
93
+
94
+ it 'should give the new groups the correct source tree property' do
95
+ @here_group.source_tree.should == "<group>"
96
+ end
97
+
98
+ it 'should give the new groups an ID' do
99
+ @here_group.source_tree.should_not be_nil
100
+ end
101
+
102
+ it 'should give the new groups a valid ISA' do
103
+ @here_group.isa.should == 'PBXGroup'
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+
110
+ context '#add_file' do
111
+
112
+ let(:first_file) { File.join(FILE_RESOURCE_PATH, "SecondViewController.h") }
113
+ let(:second_file) { File.join(FILE_RESOURCE_PATH, "SecondViewController.m") }
114
+
115
+ before :all do
116
+ @temp_path = TempProject.create(File.join(PROJECT_RESOURCE_PATH, "ProjectWithSpecs"))
117
+ @temp_project = Vendor::XCode::Project.new(File.join(@temp_path, "ProjectWithSpecs.xcodeproj"))
118
+
119
+ @target = @temp_project.find_target("Specs")
120
+
121
+ @first_file_added = @temp_project.add_file :targets => [ @target ], :file => first_file, :path => "Controllers/SecondViewController"
122
+ @second_file_added = @temp_project.add_file :targets => [ @target ], :file => second_file, :path => "Controllers/SecondViewController"
123
+ end
124
+
125
+ it 'should add the file to the filesystem' do
126
+ new_first_path = File.join(@temp_path, "Controllers", "SecondViewController", "SecondViewController.h")
127
+ new_second_path = File.join(@temp_path, "Controllers", "SecondViewController", "SecondViewController.m")
128
+
129
+ File.exists?(new_first_path).should be_true
130
+ File.exists?(new_second_path).should be_true
131
+ end
132
+
133
+ it 'should add it as the correct file type' do
134
+ @first_file_added.last_known_file_type.should == "sourcecode.c.h"
135
+ @second_file_added.last_known_file_type.should == "sourcecode.c.objc"
136
+ end
137
+
138
+ it 'should add the files with the correct path' do
139
+ @first_file_added.path.should == "SecondViewController.h"
140
+ @second_file_added.path.should == "SecondViewController.m"
141
+ end
142
+
143
+ it 'should have the correct ISA' do
144
+ @first_file_added.isa.should == "PBXFileReference"
145
+ @second_file_added.isa.should == "PBXFileReference"
146
+ end
147
+
148
+ it 'should have an ID' do
149
+ @first_file_added.id.should_not be_nil
150
+ @second_file_added.id.should_not be_nil
151
+ end
152
+
153
+ it 'should add it to the correct group' do
154
+ group = @temp_project.find_and_make_group("Controllers/SecondViewController")
155
+
156
+ group.children[0].should == @first_file_added
157
+ group.children[1].should == @second_file_added
158
+ end
159
+
160
+ it 'should still save' do
161
+ @temp_project.save
162
+ end
163
+
164
+ it 'should add it to the build targets specified'
165
+
166
+ context 'should raise an error if' do
167
+
168
+ it 'there is no target set' do
169
+ expect do
170
+ @temp_project.add_file :file => "ASD", :path => "ASD"
171
+ end.to raise_exception(StandardError, "Missing :targets option")
172
+ end
173
+
174
+ it 'there is no path set' do
175
+ expect do
176
+ @temp_project.add_file :targets => "Specs", :file => first_file
177
+ end.to raise_exception(StandardError, "Missing :path option")
178
+ end
179
+
180
+ it 'there is no file set' do
181
+ expect do
182
+ @temp_project.add_file :targets => "Specs", :path => "ASD"
183
+ end.to raise_exception(StandardError, "Missing :file option")
184
+ end
185
+
186
+ it "the file doesn't exist" do
187
+ expect do
188
+ @temp_project.add_file :targets => "Ruut", :file => "foo", :path => "Controllers/SecondViewController"
189
+ end.to raise_exception(StandardError, "Could not find file `foo`")
190
+ end
191
+
192
+ end
193
+
194
+ end
195
+
196
+ context "#to_ascii_plist" do
197
+
198
+ it "should convert it to the correct format" do
199
+ # Reload the project from the filesystem
200
+ @project.reload
201
+
202
+ contents = File.readlines(File.join(PROJECT_RESOURCE_PATH, "ProjectWithSpecs/ProjectWithSpecs.xcodeproj", "project.pbxproj")).join("\n")
203
+ original = Vendor::Plist.parse_ascii(contents)
204
+ saved = Vendor::Plist.parse_ascii(@project.to_ascii_plist)
205
+
206
+ original.should == saved
207
+ end
208
+
209
+ end
210
+
211
+ end