diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-11-08 13:35:44 +0900 |
---|---|---|
committer | git <[email protected]> | 2023-11-13 11:33:00 +0000 |
commit | 8e64c87f64508bf7192d44581632aff6dce15bf6 (patch) | |
tree | 49e5db7dafa85a0bc8aba0900a4e7fd03d6c0421 | |
parent | 50a5b76decf21f833da6c838e7acc7f991e47e00 (diff) |
[rubygems/rubygems] Make sure to `require "rubygems"` explicitly
This is also done in bundler/lib/bundler/rubygems_integration.rb, but
bundler/lib/bundler.rb loads this file before it.
https://github.com/rubygems/rubygems/commit/8840d8507b
-rw-r--r-- | lib/bundler/rubygems_ext.rb | 2 | ||||
-rw-r--r-- | spec/bundler/runtime/requiring_spec.rb | 15 | ||||
-rw-r--r-- | spec/bundler/runtime/setup_spec.rb | 6 |
3 files changed, 17 insertions, 6 deletions
diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 77e87288c3..1d5a42cbbe 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -2,6 +2,8 @@ require "pathname" +require "rubygems" unless defined?(Gem) + require "rubygems/specification" # We can't let `Gem::Source` be autoloaded in the `Gem::Specification#source` diff --git a/spec/bundler/runtime/requiring_spec.rb b/spec/bundler/runtime/requiring_spec.rb new file mode 100644 index 0000000000..58e44febed --- /dev/null +++ b/spec/bundler/runtime/requiring_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +RSpec.describe "Requiring bundler" do + it "takes care of requiring rubygems when entrypoint is bundler/setup" do + sys_exec("#{Gem.ruby} -I#{lib_dir} -rbundler/setup -e'puts true'", :env => { "RUBYOPT" => opt_add("--disable=gems", ENV["RUBYOPT"]) }) + + expect(last_command.stdboth).to eq("true") + end + + it "takes care of requiring rubygems when requiring just bundler" do + sys_exec("#{Gem.ruby} -I#{lib_dir} -rbundler -e'puts true'", :env => { "RUBYOPT" => opt_add("--disable=gems", ENV["RUBYOPT"]) }) + + expect(last_command.stdboth).to eq("true") + end +end diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index 1b1e78f6b2..6c414ccb5d 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -1506,12 +1506,6 @@ end expect(err).to include "private method `require'" end - it "takes care of requiring rubygems" do - sys_exec("#{Gem.ruby} -I#{lib_dir} -rbundler/setup -e'puts true'", :env => { "RUBYOPT" => opt_add("--disable=gems", ENV["RUBYOPT"]) }) - - expect(last_command.stdboth).to eq("true") - end - it "memoizes initial set of specs when requiring bundler/setup, so that even if further code mutates dependencies, Bundler.definition.specs is not affected" do install_gemfile <<~G source "#{file_uri_for(gem_repo1)}" |