Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
+ set spec
  • Loading branch information
alloy committed Sep 15, 2011
1 parent de7fe36 commit b7284de
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/cocoa_pods/dependency.rb
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/cocoa_pods/specification.rb
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions lib/cocoa_pods/specification/set.rb
Expand Up @@ -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.
Expand Down
76 changes: 76 additions & 0 deletions 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
17 changes: 14 additions & 3 deletions spec/unit/specification_spec.rb
Expand Up @@ -86,16 +86,27 @@
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
@spec.read(:xcconfig).should == {
'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
Expand Down

0 comments on commit b7284de

Please sign in to comment.