Skip to content

Commit

Permalink
Don't add duplicated specs to unresolved specs
Browse files Browse the repository at this point in the history
This could happen when a regular gem shadows a default gem.
  • Loading branch information
deivid-rodriguez committed Sep 26, 2024
1 parent e6e3db8 commit 9ef70dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ def activate_dependencies
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
Expand Down
16 changes: 16 additions & 0 deletions test/rubygems/test_require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,22 @@ def test_require_is_not_lazy_with_exact_req
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"
Expand Down

0 comments on commit 9ef70dd

Please sign in to comment.