Skip to content

Commit

Permalink
Merge pull request #29 from nmccann/feature/subspec_dependency_fix
Browse files Browse the repository at this point in the history
Issue 1460 Subspec dependency checking should no longer produce false-po...
  • Loading branch information
fabiopelosin committed Oct 10, 2013
2 parents 95a4eda + 610651a commit 97632f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/cocoapods-core/specification/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,17 @@ def deployment_target=(*args)
def dependency(*args)
name, *version_requirements = args
raise Informative, "A specification can't require itself as a subspec" if name == self.name
raise Informative, "A subspec can't require one of its parents specifications" if @parent && @parent.name.include?(name)
if @parent
composed_name = ""
@parent.name.split("/").each do |component|
composed_name << component
if name == composed_name
raise Informative, "A subspec can't require one of its parents specifications"
break
end
composed_name << "/"
end
end
raise Informative, "Unsupported version requirements" unless version_requirements.all? { |req| req.is_a?(String) }
attributes_hash["dependencies"] ||= {}
attributes_hash["dependencies"][name] = version_requirements
Expand Down
18 changes: 18 additions & 0 deletions spec/specification/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ module Pod
@spec.attributes_hash["dependencies"].should == {'SVStatusHUD' => []}
end

it "allows a dependency whose name matches part of one of its parents names" do
@spec.subspec 'subspectest' do |sp|
sp.subspec 'subsubspec' do |ssp|
ssp.dependency('subspec')
ssp.attributes_hash["dependencies"].should == {'subspec' => []}
end
end
end

it "raises if the specification requires itself" do
should.raise Informative do
@spec.dependency('Pod')
Expand All @@ -144,6 +153,15 @@ module Pod
should.raise Informative do
subspec.dependency('Pod')
end.message.should.match /can't require one of its parents/

#Ensure nested subspecs are prevented from requiring one of their parents
@spec.subspec 'subspec' do |sp|
sp.subspec 'subsubspec' do |ssp|
should.raise Informative do
ssp.dependency('Pod/subspec')
end.message.should.match /can't require one of its parents/
end
end
end

it "raises if the requirements are not supported" do
Expand Down

0 comments on commit 97632f1

Please sign in to comment.