diff options
| -rw-r--r-- | lib/rubygems/specification.rb | 35 | ||||
| -rw-r--r-- | test/rubygems/test_gem_specification.rb | 20 |
2 files changed, 42 insertions, 13 deletions
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index aea763abe8..5f1cb92e02 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -1199,21 +1199,30 @@ class Gem::Specification < Gem::BasicSpecification Gem.pre_reset_hooks.each(&:call) @specification_record = nil clear_load_cache - unresolved = unresolved_deps - unless unresolved.empty? - warn "WARN: Unresolved or ambiguous specs during Gem::Specification.reset:" - unresolved.values.each do |dep| - warn " #{dep}" - - 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}" } + + unless unresolved_deps.empty? + unresolved = unresolved_deps.filter_map do |name, dep| + matching_versions = find_all_by_name(name) + next if dep.latest_version? && matching_versions.any?(&:default_gem?) + + [dep, matching_versions.uniq(&:full_name)] + end.to_h + + unless unresolved.empty? + warn "WARN: Unresolved or ambiguous specs during Gem::Specification.reset:" + unresolved.each do |dep, versions| + warn " #{dep}" + + unless versions.empty? + warn " Available/installed versions of this gem:" + versions.each {|s| warn " - #{s.version}" } + end end + warn "WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'" + warn "Please report a bug if this causes problems." end - warn "WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'" - warn "Please report a bug if this causes problems." - unresolved.clear + + unresolved_deps.clear end Gem.post_reset_hooks.each(&:call) end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 77596b54f6..56f06742b3 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -3111,6 +3111,26 @@ Please report a bug if this causes problems. assert_empty specification.unresolved_deps end + def test_unresolved_specs_with_unrestricted_deps_on_default_gems + specification = Gem::Specification.clone + + set_orig specification + + spec = new_default_spec "stringio", "3.1.1" + + specification.instance_variable_set(:@unresolved_deps, { stringio: Gem::Dependency.new("stringio", ">= 0") }) + + specification.define_singleton_method(:find_all_by_name) do |_dep_name| + [spec] + end + + actual_stdout, actual_stderr = capture_output do + specification.reset + end + assert_empty actual_stdout + assert_empty actual_stderr + end + def test_duplicate_runtime_dependency expected = "WARNING: duplicated b dependency [\"~> 3.0\", \"~> 3.0\"]\n" out, err = capture_output do |
