diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 5735038ad3..d05df9cf04 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -1208,7 +1208,7 @@ class Gem::Specification < Gem::BasicSpecification unresolved.values.each do |dep| warn " #{dep}" - versions = find_all_by_name(dep.name) + versions = find_all_by_name(dep.name).uniq(&:full_name) unless versions.empty? warn " Available/installed versions of this gem:" versions.each {|s| warn " - #{s.version}" } diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 0a009cbd7b..d434ea96f3 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -3087,6 +3087,40 @@ Please report a bug if this causes problems. assert_equal(expected, actual_stderr) end + def test_unresolved_specs_with_duplicated_versions + specification = Gem::Specification.clone + + set_orig specification + + specification.define_singleton_method(:unresolved_deps) do + { b: Gem::Dependency.new("x","1") } + end + + specification.define_singleton_method(:find_all_by_name) do |_dep_name| + [ + specification.new {|s| s.name = "z", s.version = Gem::Version.new("1") }, # default copy + specification.new {|s| s.name = "z", s.version = Gem::Version.new("1") }, # regular copy + specification.new {|s| s.name = "z", s.version = Gem::Version.new("2") }, # regular copy + ] + end + + expected = <<-EXPECTED +WARN: Unresolved or ambiguous specs during Gem::Specification.reset: + x (= 1) + Available/installed versions of this gem: + - 1 + - 2 +WARN: Clearing out unresolved specs. Try 'gem cleanup ' +Please report a bug if this causes problems. + EXPECTED + + actual_stdout, actual_stderr = capture_output do + specification.reset + end + assert_empty actual_stdout + assert_equal(expected, actual_stderr) + end + def test_duplicate_runtime_dependency expected = "WARNING: duplicated b dependency [\"~> 3.0\", \"~> 3.0\"]\n" out, err = capture_output do