summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarriet Oughton <harriet.oughton@shopify.com>2026-04-13 18:09:09 +0100
committergit <svn-admin@ruby-lang.org>2026-04-14 13:08:28 +0000
commit51d9e92413e9bda4b6a441164c49ced584c73a59 (patch)
treec471037a7358feaf85d1599db73de60ac4ea0823
parentace687e261ef34c103cc3f0f9380394b660ea319 (diff)
[ruby/rubygems] Update spec_set to use lookup
https://github.com/ruby/rubygems/commit/3a90d24e42
-rw-r--r--lib/bundler/spec_set.rb4
-rw-r--r--spec/bundler/bundler/spec_set_spec.rb36
2 files changed, 38 insertions, 2 deletions
diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb
index f9179e7a06..e8d990d207 100644
--- a/lib/bundler/spec_set.rb
+++ b/lib/bundler/spec_set.rb
@@ -178,7 +178,7 @@ module Bundler
end
def find_by_name_and_platform(name, platform)
- @specs.detect {|spec| spec.name == name && spec.installable_on_platform?(platform) }
+ lookup[name]&.detect {|spec| spec.installable_on_platform?(platform) }
end
def specs_with_additional_variants_from(other)
@@ -314,7 +314,7 @@ module Bundler
end
def sorted
- @sorted ||= ([@specs.find {|s| s.name == "rake" }] + tsort).compact.uniq
+ @sorted ||= ([lookup["rake"]&.first] + tsort).compact.uniq
rescue TSort::Cyclic => error
cgems = extract_circular_gems(error)
raise CyclicDependencyError, "Your bundle requires gems that depend" \
diff --git a/spec/bundler/bundler/spec_set_spec.rb b/spec/bundler/bundler/spec_set_spec.rb
index c4b6676223..d69d0bf8fd 100644
--- a/spec/bundler/bundler/spec_set_spec.rb
+++ b/spec/bundler/bundler/spec_set_spec.rb
@@ -43,6 +43,30 @@ RSpec.describe Bundler::SpecSet do
spec = described_class.new(specs).find_by_name_and_platform("b", platform)
expect(spec).to eq platform_spec
end
+
+ it "returns nil when the name is not present" do
+ spec = described_class.new(specs).find_by_name_and_platform("missing", platform)
+ expect(spec).to be_nil
+ end
+
+ it "returns nil when the name exists but no spec is installable on the requested platform" do
+ incompatible_platform = Gem::Platform.new("java")
+ incompatible_spec = build_spec("a", "1.0", incompatible_platform).first
+
+ spec = described_class.new([incompatible_spec]).find_by_name_and_platform("a", platform)
+ expect(spec).to be_nil
+ end
+
+ it "returns the first installable spec for the given name in insertion order" do
+ later_platform_spec = build_spec("b", "3.0", platform).first
+ specs = [
+ platform_spec,
+ later_platform_spec,
+ ]
+
+ spec = described_class.new(specs).find_by_name_and_platform("b", platform)
+ expect(spec).to eq platform_spec
+ end
end
describe "#to_a" do
@@ -55,5 +79,17 @@ RSpec.describe Bundler::SpecSet do
d-2.0
]
end
+
+ it "puts rake first when present" do
+ specs = [
+ build_spec("a", "1.0") {|s| s.dep "rake", ">= 0" },
+ build_spec("rake", "13.0"),
+ ].flatten
+
+ expect(described_class.new(specs).to_a.map(&:full_name)).to eq %w[
+ rake-13.0
+ a-1.0
+ ]
+ end
end
end