diff --git a/lib/bundler.rb b/lib/bundler.rb index e8bcb33732c..1887457c779 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -299,7 +299,7 @@ def unbundled_env env.delete_if {|k, _| k[0, 7] == "BUNDLE_" } if env.key?("RUBYOPT") - env["RUBYOPT"] = env["RUBYOPT"].sub "-r#{File.expand_path("bundler/setup", __dir__)}", "" + env["RUBYOPT"] = env["RUBYOPT"].sub "-rbundler/setup", "" end if env.key?("RUBYLIB") diff --git a/spec/runtime/with_unbundled_env_spec.rb b/spec/runtime/with_unbundled_env_spec.rb index c156fa30e92..62a9e408813 100644 --- a/spec/runtime/with_unbundled_env_spec.rb +++ b/spec/runtime/with_unbundled_env_spec.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true RSpec.describe "Bundler.with_env helpers" do - def bundle_exec_ruby!(code) - build_bundler_context - bundle! "exec '#{Gem.ruby}' -e #{code}" + def bundle_exec_ruby!(code, options = {}) + build_bundler_context options + bundle! "exec '#{Gem.ruby}' -e #{code}", options end - def build_bundler_context + def build_bundler_context(options = {}) bundle "config set path vendor/bundle" gemfile "" - bundle "install" + bundle "install", options end describe "Bundler.original_env" do @@ -74,9 +74,9 @@ def build_bundler_context it "should remove '-rbundler/setup' from RUBYOPT" do code = "print #{modified_env}['RUBYOPT']" - ENV["RUBYOPT"] = "-W2 -r#{lib}/bundler/setup #{ENV["RUBYOPT"]}" - bundle_exec_ruby! code.dump - expect(last_command.stdboth).not_to include("-r#{lib}/bundler/setup") + ENV["RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}" + bundle_exec_ruby! code.dump, :env => { "BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM" => "true" } + expect(last_command.stdboth).not_to include("-rbundler/setup") end it "should restore RUBYLIB", :ruby_repo do diff --git a/spec/support/hax.rb b/spec/support/hax.rb index 9a4975c140b..e5e8ce2c697 100644 --- a/spec/support/hax.rb +++ b/spec/support/hax.rb @@ -14,7 +14,7 @@ class Platform @platforms = [Gem::Platform::RUBY, Gem::Platform.local] # We only need this hack for rubygems versions without the BundlerVersionFinder - if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") + if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") || ENV["BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM"] @path_to_default_spec_map.delete_if do |_path, spec| spec.name == "bundler" end