diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index d05df9cf04..e5541e57b1 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -1412,7 +1412,7 @@ class Gem::Specification < Gem::BasicSpecification end begin - specs = spec_dep.to_specs + specs = spec_dep.to_specs.uniq(&:full_name) rescue Gem::MissingSpecError => e raise Gem::MissingSpecError.new(e.name, e.requirement, "at: #{spec_file}") end diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index b915a86197..48d66736fd 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -182,6 +182,22 @@ class TestGemRequire < Gem::TestCase assert_equal %w[a-1 b-1], loaded_spec_names end + def test_require_is_not_lazy_with_shadowed_default_gem + b1_default = new_default_spec("b", "1", nil, "foo.rb") + install_default_gems b1_default + + a1 = util_spec "a", "1", { "b" => ">= 1" }, "lib/test_gem_require_a.rb" + b1 = util_spec("b", "1", nil, "lib/foo.rb") + install_specs b1, a1 + + # Load default ruby gems fresh as if we've just started a ruby script. + Gem::Specification.reset + + assert_require "test_gem_require_a" + assert_equal %w[a-1 b-1], loaded_spec_names + assert_equal unresolved_names, [] + end + def test_require_is_lazy_with_inexact_req a1 = util_spec "a", "1", { "b" => ">= 1" }, "lib/test_gem_require_a.rb" b1 = util_spec "b", "1", nil, "lib/b/c.rb"