Skip to content

Commit

Permalink
[rubygems/rubygems] Override initialize in bundle rubygems_ext for Na…
Browse files Browse the repository at this point in the history
  • Loading branch information
martinemde authored and matzbot committed Dec 11, 2023
1 parent b673b5b commit e186ceb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/bundler/rubygems_ext.rb
Expand Up @@ -352,11 +352,16 @@ def extensions_dir
require "rubygems/name_tuple"

class NameTuple
def self.new(name, version, platform="ruby")
if Gem::Platform === platform
super(name, version, platform.to_s)
else
super
# Versions of RubyGems before about 3.5.0 don't to_s the platform.
unless Gem::NameTuple.new("a", Gem::Version.new("1"), Gem::Platform.new("x86_64-linux")).platform.is_a?(String)
alias_method :initialize_with_platform, :initialize

def initialize(name, version, platform=Gem::Platform::RUBY)
if Gem::Platform === platform
initialize_with_platform(name, version, platform.to_s)
else
initialize_with_platform(name, version, platform)
end
end
end

Expand Down
20 changes: 20 additions & 0 deletions spec/bundler/other/ext_spec.rb
Expand Up @@ -63,3 +63,23 @@
run "Gem::SourceIndex.new([]).refresh!", raise_on_error: false
end
end

RSpec.describe "Gem::NameTuple" do
describe "#initialize" do
it "creates a Gem::NameTuple with equality regardless of platform type" do
gem_platform = Gem::NameTuple.new "a", v("1"), pl("x86_64-linux")
str_platform = Gem::NameTuple.new "a", v("1"), "x86_64-linux"
expect(gem_platform).to eq(str_platform)
expect(gem_platform.hash).to eq(str_platform.hash)
expect(gem_platform.to_a).to eq(str_platform.to_a)
end
end

describe "#lock_name" do
it "returns the lock name" do
expect(Gem::NameTuple.new("a", v("1.0.0"), pl("x86_64-linux")).lock_name).to eq("a (1.0.0-x86_64-linux)")
expect(Gem::NameTuple.new("a", v("1.0.0"), "ruby").lock_name).to eq("a (1.0.0)")
expect(Gem::NameTuple.new("a", v("1.0.0")).lock_name).to eq("a (1.0.0)")
end
end
end

0 comments on commit e186ceb

Please sign in to comment.