Skip to content
Browse files

+ set spec

  • Loading branch information...
1 parent de7fe36 commit b7284de3612ca45f541f72fe577a99556ad9dbaf @alloy alloy committed
View
1 lib/cocoa_pods/dependency.rb
@@ -5,6 +5,7 @@ module Gem
module Pod
class Dependency < Gem::Dependency
attr_accessor :only_part_of_other_pod
+ alias_method :only_part_of_other_pod?, :only_part_of_other_pod
def initialize(name, *version_requirements)
super
View
10 lib/cocoa_pods/specification.rb
@@ -94,6 +94,16 @@ def xcconfig(hash)
include Config::Mixin
+ def ==(other)
+ self.class === other &&
+ @name && @name == other.read(:name) &&
+ @version && @version == other.read(:version)
+ end
+
+ def dependency_by_name(name)
+ @dependencies.find { |d| d.name == name }
+ end
+
# Returns the specification for the pod that this pod's source is a part of.
def part_of_specification
if @part_of
View
19 lib/cocoa_pods/specification/set.rb
@@ -24,34 +24,37 @@ def initialize(pod_dir)
@required_by = []
end
- def required_by(specification, dependency)
+ def required_by(specification)
+ dependency = specification.dependency_by_name(name)
unless @required_by.empty? || dependency.requirement.satisfied_by?(required_version)
# TODO add graph that shows which dependencies led to this.
- required_by = @required_by.map(&:first).join(', ')
raise "#{specification} tries to activate `#{dependency}', " \
- "but already activated version `#{required_version}' by #{required_by}."
+ "but already activated version `#{required_version}' " \
+ "by #{@required_by.join(', ')}."
end
- @required_by << [specification, dependency]
+ @required_by << specification
end
def dependency
- @required_by.inject(Dependency.new(name)) { |previous, (_, dep)| previous.merge(dep) }
+ @required_by.inject(Dependency.new(name)) do |previous, spec|
+ previous.merge(spec.dependency_by_name(name))
+ end
end
def only_part_of_other_pod?
- @required_by.all? { |_, dep| dep.only_part_of_other_pod }
+ @required_by.all? { |spec| spec.dependency_by_name(name).only_part_of_other_pod? }
end
def name
@pod_dir.basename.to_s
end
- def spec_pathname
+ def specification_path
@pod_dir + required_version.to_s + "#{name}.podspec"
end
def specification
- Specification.from_podspec(spec_pathname)
+ Specification.from_podspec(specification_path)
end
# Return the first version that matches the current dependency.
View
76 spec/unit/specification/set_spec.rb
@@ -0,0 +1,76 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+class Pod::Spec::Set
+ def reset!
+ @required_by = []
+ end
+end
+
+describe "Pod::Specification::Set" do
+ it "returns nil in case a set hasn't been resolved yet" do
+ Pod::Spec::Set.by_specification_name('ASIHTTPRequest').should == nil
+ end
+
+ before do
+ @set = Pod::Spec::Set.by_pod_dir(fixture('spec-repos/master/ASIHTTPRequest'))
+ @set.reset!
+ end
+
+ it "returns a cached set by name once it has been resolved once" do
+ Pod::Spec::Set.by_specification_name('ASIHTTPRequest').should.eql @set
+ end
+
+ it "always returns the same set instance for a pod dir" do
+ Pod::Spec::Set.by_pod_dir(fixture('spec-repos/master/ASIHTTPRequest')).should.eql @set
+ end
+
+ it "returns the name of the pod" do
+ @set.name.should == 'ASIHTTPRequest'
+ end
+
+ it "returns the versions available for this pod ordered from highest to lowest" do
+ @set.versions.should == [Pod::Version.new('1.8.1'), Pod::Version.new('1.8')]
+ end
+
+ it "checks if the dependency of the specification is compatible with existing requirements" do
+ @set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '1.8' })
+ @set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8.1' })
+ @set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '> 1.7.9' })
+ @set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '~> 1.8.0' })
+ @set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest' })
+ lambda { @set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8' }) }.should.raise
+ end
+
+ it "raises if the required version doesn't exist" do
+ @set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8' })
+ lambda { @set.required_version }.should.raise
+ end
+
+ before do
+ @set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8.1' })
+ end
+
+ it "returns the version required for the dependency" do
+ @set.required_version.should == Pod::Version.new('1.8')
+ end
+
+ it "returns the path to the specification for the required version" do
+ @set.specification_path.should == fixture('spec-repos/master/ASIHTTPRequest/1.8/ASIHTTPRequest.podspec')
+ end
+
+ it "returns the specification for the required version" do
+ @set.specification.should == Pod::Spec.new { name 'ASIHTTPRequest'; version '1.8' }
+ end
+
+ it "returns that this set is not only part for other pods" do
+ @set.required_by(Pod::Spec.new { part_of 'ASIHTTPRequest' })
+ @set.should.not.be.only_part_of_other_pod
+ end
+
+ it "returns that this set is only part for other pods" do
+ @set.reset!
+ @set.required_by(Pod::Spec.new { part_of 'ASIHTTPRequest' })
+ @set.required_by(Pod::Spec.new { part_of 'ASIHTTPRequest' })
+ @set.should.be.only_part_of_other_pod
+ end
+end
View
17 spec/unit/specification_spec.rb
@@ -86,9 +86,9 @@
end
it "returns the pod's dependencies" do
- @spec.read(:dependencies).should == [
- Pod::Dependency.new('monkey', '~> 1.0.1', '< 1.0.9')
- ]
+ expected = Pod::Dependency.new('monkey', '~> 1.0.1', '< 1.0.9')
+ @spec.read(:dependencies).should == [expected]
+ @spec.dependency_by_name('monkey').should == expected
end
it "returns the pod's xcconfig settings" do
@@ -96,6 +96,17 @@
'OTHER_LDFLAGS' => '-framework SystemConfiguration'
}
end
+
+ it "returns that it's equal to another specification if the name and version are equal" do
+ @spec.should == Pod::Spec.new { name 'BananaLib'; version '1.0' }
+ @spec.should.not == Pod::Spec.new { name 'OrangeLib'; version '1.0' }
+ @spec.should.not == Pod::Spec.new { name 'BananaLib'; version '1.1' }
+ @spec.should.not == Pod::Spec.new
+ end
+
+ it "never equals when it's from a Podfile" do
+ Pod::Spec.new.should.not == Pod::Spec.new
+ end
end
describe "A Pod::Specification that's part of another pod's source" do

0 comments on commit b7284de

Please sign in to comment.
Something went wrong with that request. Please try again.