From 73834f11fa22ab963df064f7a6fe34c6a0488468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 7 Oct 2024 17:31:42 +0200 Subject: [PATCH] [rubygems/rubygems] Fix `Gem::Specification#gem_dir` losing custom source for some reason https://github.com/rubygems/rubygems/commit/f8f589b1b8 --- lib/bundler/rubygems_ext.rb | 7 +++++++ lib/rubygems/specification.rb | 8 -------- spec/bundler/runtime/setup_spec.rb | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 67f830d4f3..a3f70e9a3c 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -123,6 +123,13 @@ module Gem end end + # Can be removed once RubyGems 3.5.21 support is dropped + remove_method :gem_dir if method_defined?(:gem_dir, false) + + def gem_dir + full_gem_path + end + unless const_defined?(:LATEST_RUBY_WITHOUT_PATCH_VERSIONS) LATEST_RUBY_WITHOUT_PATCH_VERSIONS = Gem::Version.new("2.1") diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index e5541e57b1..4753186a83 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -1912,14 +1912,6 @@ class Gem::Specification < Gem::BasicSpecification @full_name ||= super end - ## - # Work around old bundler versions removing my methods - # Can be removed once RubyGems can no longer install Bundler 2.5 - - def gem_dir # :nodoc: - super - end - def gems_dir @gems_dir ||= File.join(base_dir, "gems") end diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index fc574f3196..58f2293109 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -706,6 +706,21 @@ RSpec.describe "Bundler.setup" do expect(out).to be_empty end + it "has gem_dir pointing to local repo" do + build_lib "foo", "1.0", path: bundled_app + + install_gemfile <<-G + source "https://gem.repo1" + gemspec + G + + run <<-R + puts Gem.loaded_specs['foo'].gem_dir + R + + expect(out).to eq(bundled_app.to_s) + end + it "does not load all gemspecs" do install_gemfile <<-G source "https://gem.repo1"