Browse files

+ specification specs

  • Loading branch information...
1 parent deb4712 commit ff706d0941402a91c94f3491d782f00bf18a901b @alloy alloy committed Sep 14, 2011
View
12 lib/cocoa_pods/dependency.rb
@@ -4,8 +4,18 @@ module Gem
module Pod
class Dependency < Gem::Dependency
- attr_accessor :part_of_other_pod
+ attr_accessor :only_part_of_other_pod
+ def initialize(name, *version_requirements)
+ super
+ @only_part_of_other_pod = false
+ end
+
+ def ==(other)
+ super && @only_part_of_other_pod == other.only_part_of_other_pod
+ end
+
+ # Taken from a newer version of RubyGems
unless public_method_defined?(:merge)
def merge other
unless name == other.name then
View
20 lib/cocoa_pods/specification.rb
@@ -3,17 +3,17 @@
module Pod
class Specification
def self.from_podfile(path)
- if File.exist?(path)
+ if path.exist?
spec = new
- spec.instance_eval(File.read(path))
+ spec.instance_eval(path.read)
spec.defined_in_file = path
spec
end
end
- def self.from_podspec(pathname)
- spec = eval(File.read(pathname), nil, pathname.to_s)
- spec.defined_in_file = pathname
+ def self.from_podspec(path)
+ spec = eval(path.read, nil, path.to_s)
+ spec.defined_in_file = path
spec
end
@@ -63,17 +63,16 @@ def description(description)
end
def part_of(name, *version_requirements)
- @part_of = dependency(name, *version_requirements)
- @part_of.part_of_other_pod = true
+ part_of_dependency(name, *version_requirements)
+ @part_of.only_part_of_other_pod = true
end
def part_of_dependency(name, *version_requirements)
- part_of(name, *version_requirements)
- dependency(name, *version_requirements)
+ @part_of = dependency(name, *version_requirements)
end
def source_files(*patterns)
- @source_files = patterns
+ @source_files = patterns.map { |p| Pathname.new(p) }
end
def source(remote)
@@ -103,6 +102,7 @@ def part_of_specification
end
def pod_destroot
+ return if from_podfile?
if part_of_other_pod?
part_of_specification.pod_destroot
else
View
2 lib/cocoa_pods/specification/set.rb
@@ -37,7 +37,7 @@ def dependency
end
def only_part_of_other_pod?
- @required_by.all? { |_, dep| dep.part_of_other_pod }
+ @required_by.all? { |_, dep| dep.only_part_of_other_pod }
end
def name
View
4 spec/fixtures/Podfile
@@ -0,0 +1,4 @@
+dependency 'SSZipArchive', '>= 1'
+dependency 'ASIHTTPRequest', '~> 1.8.0'
+dependency 'Reachability' # part of ASIHTTPRequest
+dependency 'ASIWebPageRequest', '< 1.8.2' # part of ASIHTTPRequest
2 spec/fixtures/banana-lib
@@ -1 +1 @@
-Subproject commit f046c1a0fc673a01cf1ce4607c5d1857ce08b44a
+Subproject commit 0d06750e78e5a6653dc0f66776a257052328c146
View
9 spec/unit/dependency_spec.rb
@@ -6,4 +6,13 @@
dep2 = Pod::Dependency.new('bananas', '1.9')
dep1.merge(dep2).should == Pod::Dependency.new('bananas', '>= 1.8', '1.9')
end
+
+ it "is equal to another dependency if the `part_of_other_pod' flag is the same" do
+ dep1 = Pod::Dependency.new('bananas', '>= 1')
+ dep1.only_part_of_other_pod = true
+ dep2 = Pod::Dependency.new('bananas', '>= 1')
+ dep1.should.not == dep2
+ dep2.only_part_of_other_pod = true
+ dep1.should == dep2
+ end
end
View
129 spec/unit/specification_spec.rb
@@ -0,0 +1,129 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+describe "A Pod::Specification loaded from a Podfile" do
+ before do
+ @spec = Pod::Specification.from_podfile(fixture('Podfile'))
+ end
+
+ it "lists the project's dependencies" do
+ @spec.dependencies.should == [
+ Pod::Dependency.new('SSZipArchive', '>= 1'),
+ Pod::Dependency.new('ASIHTTPRequest', '~> 1.8.0'),
+ Pod::Dependency.new('Reachability', '>= 0'),
+ Pod::Dependency.new('ASIWebPageRequest', ' < 1.8.2')
+ ]
+ end
+
+ it "returns the path to the Podfile" do
+ @spec.defined_in_file.should == fixture('Podfile')
+ end
+
+ it "returns that it's loaded from a Podfile" do
+ @spec.should.be.from_podfile
+ end
+
+ it "does not have a destroot" do
+ @spec.pod_destroot.should == nil
+ end
+end
+
+describe "A Pod::Specification loaded from a podspec" do
+ before do
+ @spec = Pod::Specification.from_podspec(fixture('banana-lib/BananaLib.podspec'))
+ end
+
+ it "returns that it's not loaded from a podfile" do
+ @spec.should.not.be.from_podfile
+ end
+
+ it "returns the path to the podspec" do
+ @spec.defined_in_file.should == fixture('banana-lib/BananaLib.podspec')
+ end
+
+ it "returns the directory where the pod should be checked out to" do
+ @spec.pod_destroot.should == config.project_pods_root + 'BananaLib-1.0'
+ end
+
+ it "returns the pod's name" do
+ @spec.read(:name).should == 'BananaLib'
+ end
+
+ it "returns the pod's version" do
+ @spec.read(:version).should == Pod::Version.new('1.0')
+ end
+
+ it "returns a list of authors and their email addresses" do
+ @spec.read(:authors).should == {
+ 'Banana Corp' => nil,
+ 'Monkey Boy' => 'monkey@banana-corp.local'
+ }
+ end
+
+ it "returns the pod's homepage" do
+ @spec.read(:homepage).should == 'http://banana-corp.local/banana-lib.html'
+ end
+
+ it "returns the pod's summary" do
+ @spec.read(:summary).should == 'Chunky bananas!'
+ end
+
+ it "returns the pod's description" do
+ @spec.read(:description).should == 'Full of chunky bananas.'
+ end
+
+ it "returns the pod's source" do
+ @spec.read(:source).should == {
+ :git => 'http://banana-corp.local/banana-lib.git',
+ :tag => 'v1.0'
+ }
+ end
+
+ it "returns the pod's source files" do
+ @spec.read(:source_files).should == [
+ Pathname.new('Classes/*.{h,m}'),
+ Pathname.new('Vendor')
+ ]
+ end
+
+ it "returns the pod's dependencies" do
+ @spec.read(:dependencies).should == [
+ Pod::Dependency.new('monkey', '~> 1.0.1', '< 1.0.9')
+ ]
+ end
+
+ it "returns the pod's xcconfig settings" do
+ @spec.read(:xcconfig).should == {
+ 'OTHER_LDFLAGS' => '-framework SystemConfiguration'
+ }
+ end
+end
+
+describe "A Pod::Specification that's part of another pod's source" do
+ before do
+ @spec = Pod::Specification.new
+ end
+
+ it "adds a dependency on the other pod's source, but not the library" do
+ @spec.part_of 'monkey', '>= 1'
+ @spec.should.be.part_of_other_pod
+ dep = Pod::Dependency.new('monkey', '>= 1')
+ @spec.read(:dependencies).should.not == [dep]
+ dep.only_part_of_other_pod = true
+ @spec.read(:dependencies).should == [dep]
+ end
+
+ it "adds a dependency on the other pod's source *and* the library" do
+ @spec.part_of_dependency 'monkey', '>= 1'
+ @spec.should.be.part_of_other_pod
+ @spec.read(:dependencies).should == [Pod::Dependency.new('monkey', '>= 1')]
+ end
+
+ # TODO
+ #it "returns the specification of the pod that it's part of" do
+ # @spec.part_of_specification
+ #end
+ #
+ #it "returns the destroot of the pod that it's part of" do
+ # @spec.pod_destroot
+ #end
+end

0 comments on commit ff706d0

Please sign in to comment.