Skip to content

Commit 5d05ee5

Browse files
authored
Merge pull request #9392 from Shopify/ec-self-reference
Raise an error when building a gem that has a self reference
2 parents cc86612 + fa46739 commit 5d05ee5

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

lib/rubygems/specification_policy.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,14 @@ def validate_duplicate_dependencies # :nodoc:
192192
# Checks that the gem does not depend on itself.
193193

194194
def validate_dependencies # :nodoc:
195-
warning_messages = []
195+
error_messages = []
196196
@specification.dependencies.each do |dep|
197-
if dep.name == @specification.name # warn on self reference
198-
warning_messages << "Self referencing dependency is unnecessary and strongly discouraged."
197+
if dep.name == @specification.name # error on self reference
198+
error_messages << "Dependencies of this gem include a self-reference."
199199
end
200200
end
201-
if warning_messages.any?
202-
warning_messages.each {|warning_message| warning warning_message }
203-
end
201+
202+
error error_messages.join if error_messages.any?
204203
end
205204

206205
def validate_required_ruby_version

test/rubygems/test_gem_specification.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,14 +2812,13 @@ def test_validate_self_referencing_dependencies
28122812
Dir.chdir @tempdir do
28132813
@a1.add_dependency @a1.name, "1"
28142814

2815-
use_ui @ui do
2815+
e = assert_raise Gem::InvalidSpecificationException do
28162816
@a1.validate
28172817
end
28182818

2819-
assert_equal <<-EXPECTED, @ui.error
2820-
#{w}: Self referencing dependency is unnecessary and strongly discouraged.
2821-
#{w}: See https://guides.rubygems.org/specification-reference/ for help
2822-
EXPECTED
2819+
expected = "Dependencies of this gem include a self-reference."
2820+
2821+
assert_equal expected, e.message
28232822
end
28242823
end
28252824

0 commit comments

Comments
 (0)