lib/xcodeproject/spec/pbx_group_spec.rb in xcodeproject-0.1.1 vs lib/xcodeproject/spec/pbx_group_spec.rb in xcodeproject-0.2.3

- old
+ new

@@ -1,8 +1,8 @@ require "spec_helper" -describe XCodeProject::PBXGroup do +describe XcodeProject::PBXGroup do let(:root) { prepare_example_project.read.send(:root) } let(:obj) { root.project.main_group.group('group1a') } describe "#children" do context "if children exists" do @@ -19,10 +19,54 @@ empty_group_obj.children.size.should eql(0) end end end + describe "#files" do + context "if children exists" do + it "Returns an array of only those children who are files" do + chs = obj.files + chs.should be_an_instance_of(Array) + chs.size.should > 0 + chs.each do |child| + child.should be_an_instance_of(XcodeProject::PBXFileReference) + end + end + end + context "if children doesn't exist" do + let(:obj) { root.project.main_group.group("group1a/dir2c") } + + it "returns an empty array" do + chs = obj.files + chs.should be_an_instance_of(Array) + chs.size.should eql(0) + end + end + end + + describe "#groups" do + context "if children exists" do + it "Returns an array of only those children who are group" do + chs = obj.groups + chs.should be_an_instance_of(Array) + chs.size.should > 0 + chs.each do |child| + child.should be_an_instance_of(XcodeProject::PBXGroup) + end + end + end + context "if children doesn't exist" do + let(:obj) { root.project.main_group.group("group1a/dir2c/dir3a/dir4a") } + + it "returns an empty array" do + chs = obj.groups + chs.should be_an_instance_of(Array) + chs.size.should eql(0) + end + end + end + describe "#child" do context "if passed '.'" do it "returns the self" do obj.child('.').uuid.should eql(obj.uuid) end @@ -99,11 +143,11 @@ end describe "#group" do context "if the group exists" do it "returns the object" do - obj.group('group2a').should be_an_instance_of(XCodeProject::PBXGroup) + obj.group('group2a').should be_an_instance_of(XcodeProject::PBXGroup) end end context "if the group doesn't exist" do it "returns nil" do obj.group('group2a_ghost').should be_nil @@ -112,11 +156,11 @@ end describe "#file_ref" do context "if the file reference exists" do it "returns the object" do - obj.file_ref('file2c.m').should be_an_instance_of(XCodeProject::PBXFileReference) + obj.file_ref('file2c.m').should be_an_instance_of(XcodeProject::PBXFileReference) end end context "if the file reference doesn't exist" do it "returns nil" do obj.file_ref('file2c_ghost.m').should be_nil @@ -125,43 +169,43 @@ end describe "#add_file_ref" do context "if passed the relative path" do it "adds the file reference, returns the object" do - obj.send(:add_file_ref, 'dir1b/file2b.m').should be_an_instance_of(XCodeProject::PBXFileReference) + obj.send(:add_file_ref, 'dir1b/file2b.m').should be_an_instance_of(XcodeProject::PBXFileReference) end end context "if passed the absolute path" do it "adds the file reference, returns the object" do - obj.send(:add_file_ref, "#{example_project_dir}/dir1b/file2b.m").should be_an_instance_of(XCodeProject::PBXFileReference) + obj.send(:add_file_ref, "#{example_project_dir}/dir1b/file2b.m").should be_an_instance_of(XcodeProject::PBXFileReference) end end context "if file reference already exists" do it "new object has same uuid as existing" do uuid = obj.file_ref('file2c.m').uuid obj.send(:add_file_ref, 'dir1c/file2c.m').uuid.should eql(uuid) end end context "if file doesn't exit" do it "raise an exception " do - lambda { obj.send(:add_file_ref, "file2c_ghost.m") }.should raise_exception(XCodeProject::FilePathError) + lambda { obj.send(:add_file_ref, "file2c_ghost.m") }.should raise_exception(XcodeProject::FilePathError) end end end describe "#add_group" do it "adds the group, returns the object" do group_obj = obj.add_group("group2a_ghost") - group_obj.should be_an_instance_of(XCodeProject::PBXGroup) + group_obj.should be_an_instance_of(XcodeProject::PBXGroup) group_obj.group?.should eql(true) end end describe "#add_dir" do it "adds the group, returns the object" do group_obj = obj.add_dir("dir1c") - group_obj.should be_an_instance_of(XCodeProject::PBXGroup) + group_obj.should be_an_instance_of(XcodeProject::PBXGroup) group_obj.dir?.should eql(true) end it "adds all dir's children" do obj.add_dir('dir1c') [ @@ -170,28 +214,28 @@ obj.file('dir1c/file2c.m') ].each {|obj| obj.should_not be_nil } end context "if dir doesn't exit" do it "raise an exception " do - lambda { obj.add_dir("dir2c_ghost") }.should raise_exception(XCodeProject::FilePathError) + lambda { obj.add_dir("dir2c_ghost") }.should raise_exception(XcodeProject::FilePathError) end end end describe "#create_group" do context "if passed a group name" do it "creates and returns the group object" do - obj.create_group('group2a_ghost').should be_an_instance_of(XCodeProject::PBXGroup) + obj.create_group('group2a_ghost').should be_an_instance_of(XcodeProject::PBXGroup) end end context "if passed a group path" do it "creates missed groups and returns the last group object" do [ 'group2a/group3a_ghost', 'group2a_ghost/group3a_ghost', 'group2a_ghost/../create_group2a_ghost/./group3a_ghost' ].each do |gpath| - obj.create_group(gpath).should be_an_instance_of(XCodeProject::PBXGroup) + obj.create_group(gpath).should be_an_instance_of(XcodeProject::PBXGroup) end end end context "if group already exists" do it "new object has same uuid as existing" do