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"