From 4756c5f7e79642484d01a7dbca17357eb8b08ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 23 Jul 2019 18:44:21 +0200 Subject: [PATCH] [bundler/bundler] Remove unnecessary rubygems monkeypatch Instead, make sure we always load the local copy of bundler during specs, and never end up using the default copy. https://github.com/bundler/bundler/commit/ac655ffeda --- spec/bundler/commands/pristine_spec.rb | 3 +- spec/bundler/install/gemfile/groups_spec.rb | 2 +- spec/bundler/realworld/double_check_spec.rb | 4 +- spec/bundler/runtime/inline_spec.rb | 6 +- spec/bundler/runtime/load_spec.rb | 2 +- spec/bundler/runtime/require_spec.rb | 2 +- spec/bundler/runtime/setup_spec.rb | 58 +++++++++---------- .../runtime/with_unbundled_env_spec.rb | 12 ++-- spec/bundler/support/artifice/endpoint.rb | 2 +- spec/bundler/support/hax.rb | 3 +- spec/bundler/support/helpers.rb | 2 +- 11 files changed, 48 insertions(+), 48 deletions(-) diff --git a/spec/bundler/commands/pristine_spec.rb b/spec/bundler/commands/pristine_spec.rb index 252bef6d0d..aa5c2213d1 100644 --- a/spec/bundler/commands/pristine_spec.rb +++ b/spec/bundler/commands/pristine_spec.rb @@ -42,8 +42,7 @@ RSpec.describe "bundle pristine", :ruby_repo do expect(changes_txt).to_not be_file end - it "does not delete the bundler gem", :rubygems => ">= 2.6.2" do - ENV["BUNDLER_SPEC_KEEP_DEFAULT_BUNDLER_GEM"] = "true" + it "does not delete the bundler gem" do system_gems :bundler bundle! "install" bundle! "pristine", :system_bundler => true diff --git a/spec/bundler/install/gemfile/groups_spec.rb b/spec/bundler/install/gemfile/groups_spec.rb index b38e8b43d5..93798ef62e 100644 --- a/spec/bundler/install/gemfile/groups_spec.rb +++ b/spec/bundler/install/gemfile/groups_spec.rb @@ -333,7 +333,7 @@ RSpec.describe "bundle install with groups" do G ruby <<-R - require "bundler" + require "#{lib}/bundler" Bundler.setup :default Bundler.require :default puts RACK diff --git a/spec/bundler/realworld/double_check_spec.rb b/spec/bundler/realworld/double_check_spec.rb index 07593ac493..323e0d5735 100644 --- a/spec/bundler/realworld/double_check_spec.rb +++ b/spec/bundler/realworld/double_check_spec.rb @@ -25,9 +25,9 @@ RSpec.describe "double checking sources", :realworld => true, :sometimes => true RUBY cmd = <<-RUBY - require "bundler" + require "#{lib}/bundler" require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump} - require "bundler/inline" + require "#{lib}/bundler/inline" gemfile(true) do source "https://rubygems.org" gem "rails", path: "." diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index 6168c0c197..c3d632d75d 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "bundler/inline#gemfile" do def script(code, options = {}) - requires = ["bundler/inline"] + requires = ["#{lib}/bundler/inline"] requires.unshift File.expand_path("../../support/artifice/" + options.delete(:artifice) + ".rb", __FILE__) if options.key?(:artifice) requires = requires.map {|r| "require '#{r}'" }.join("\n") @out = ruby("#{requires}\n\n" + code, options) @@ -96,7 +96,7 @@ RSpec.describe "bundler/inline#gemfile" do it "lets me use my own ui object" do script <<-RUBY, :artifice => "endpoint" - require 'bundler' + require '#{lib}/bundler' class MyBundlerUI < Bundler::UI::Silent def confirm(msg, newline = nil) puts "CONFIRMED!" @@ -140,7 +140,7 @@ RSpec.describe "bundler/inline#gemfile" do it "does not mutate the option argument" do script <<-RUBY - require 'bundler' + require '#{lib}/bundler' options = { :ui => Bundler::UI::Shell.new } gemfile(false, options) do path "#{lib_path}" do diff --git a/spec/bundler/runtime/load_spec.rb b/spec/bundler/runtime/load_spec.rb index 80ad692769..b7dc509f6f 100644 --- a/spec/bundler/runtime/load_spec.rb +++ b/spec/bundler/runtime/load_spec.rb @@ -80,7 +80,7 @@ RSpec.describe "Bundler.load" do G ruby! <<-RUBY - require "bundler" + require "#{lib}/bundler" Bundler.setup :default Bundler.require :default puts RACK diff --git a/spec/bundler/runtime/require_spec.rb b/spec/bundler/runtime/require_spec.rb index 016fc14dfe..7874a86c32 100644 --- a/spec/bundler/runtime/require_spec.rb +++ b/spec/bundler/runtime/require_spec.rb @@ -193,7 +193,7 @@ RSpec.describe "Bundler.require" do G cmd = <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.require RUBY ruby(cmd) diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index c24e951a4f..9fa6e1bf9b 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -12,7 +12,7 @@ RSpec.describe "Bundler.setup" do G ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup require 'rack' @@ -34,7 +34,7 @@ RSpec.describe "Bundler.setup" do it "doesn't make all groups available" do ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default) begin @@ -49,7 +49,7 @@ RSpec.describe "Bundler.setup" do it "accepts string for group name" do ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default, 'test') require 'rack' @@ -61,7 +61,7 @@ RSpec.describe "Bundler.setup" do it "leaves all groups available if they were already" do ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup Bundler.setup(:default) @@ -74,7 +74,7 @@ RSpec.describe "Bundler.setup" do it "leaves :default available if setup is called twice" do ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default) Bundler.setup(:default, :test) @@ -91,7 +91,7 @@ RSpec.describe "Bundler.setup" do it "handles multiple non-additive invocations" do ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default, :test) Bundler.setup(:default) require 'rack' @@ -122,7 +122,7 @@ RSpec.describe "Bundler.setup" do ENV["RUBYLIB"] = "rubylib_dir" ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup puts $LOAD_PATH RUBY @@ -144,7 +144,7 @@ RSpec.describe "Bundler.setup" do G ruby! <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup puts $LOAD_PATH RUBY @@ -172,7 +172,7 @@ RSpec.describe "Bundler.setup" do G ruby! <<-RUBY - require 'bundler/setup' + require '#{lib}/bundler/setup' puts $LOAD_PATH RUBY @@ -193,7 +193,7 @@ RSpec.describe "Bundler.setup" do G ruby <<-R - require 'bundler' + require '#{lib}/bundler' begin Bundler.setup @@ -213,7 +213,7 @@ RSpec.describe "Bundler.setup" do G ruby <<-R - require 'bundler' + require '#{lib}/bundler' Bundler.setup R @@ -236,7 +236,7 @@ RSpec.describe "Bundler.setup" do G ruby <<-R - require 'bundler' + require '#{lib}/bundler' Bundler.setup R @@ -289,7 +289,7 @@ RSpec.describe "Bundler.setup" do ENV["BUNDLE_GEMFILE"] = "Gemfile" ruby <<-R - require 'bundler' + require '#{lib}/bundler' begin Bundler.setup @@ -444,7 +444,7 @@ RSpec.describe "Bundler.setup" do break_git! ruby <<-R - require 'bundler' + require '#{lib}/bundler' begin Bundler.setup @@ -465,7 +465,7 @@ RSpec.describe "Bundler.setup" do break_git! ruby <<-R - require "bundler" + require "#{lib}/bundler" begin Bundler.setup @@ -774,7 +774,7 @@ end s.class.send(:define_method, :build_extensions) { nil } end - require 'bundler' + require '#{lib}/bundler' gem '#{gem_name}' puts $LOAD_PATH.count {|path| path =~ /#{gem_name}/} >= 2 @@ -1028,7 +1028,7 @@ end bundle "install" ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' def Bundler.require(path) raise "LOSE" end @@ -1083,7 +1083,7 @@ end context "is not present" do it "does not change the lock" do lockfile lock_with(nil) - ruby "require 'bundler/setup'" + ruby "require '#{lib}/bundler/setup'" lockfile_should_be lock_with(nil) end end @@ -1091,7 +1091,7 @@ end context "is newer" do it "does not change the lock or warn" do lockfile lock_with(Bundler::VERSION.succ) - ruby "require 'bundler/setup'" + ruby "require '#{lib}/bundler/setup'" expect(out).to eq("") expect(err).to eq("") lockfile_should_be lock_with(Bundler::VERSION.succ) @@ -1101,7 +1101,7 @@ end context "is older" do it "does not change the lock" do lockfile lock_with("1.10.1") - ruby "require 'bundler/setup'" + ruby "require '#{lib}/bundler/setup'" lockfile_should_be lock_with("1.10.1") end end @@ -1148,14 +1148,14 @@ end context "is not present" do it "does not change the lock" do - expect { ruby! "require 'bundler/setup'" }.not_to change { lockfile } + expect { ruby! "require '#{lib}/bundler/setup'" }.not_to change { lockfile } end end context "is newer" do let(:ruby_version) { "5.5.5" } it "does not change the lock or warn" do - expect { ruby! "require 'bundler/setup'" }.not_to change { lockfile } + expect { ruby! "require '#{lib}/bundler/setup'" }.not_to change { lockfile } expect(out).to eq("") expect(err).to eq("") end @@ -1164,7 +1164,7 @@ end context "is older" do let(:ruby_version) { "1.0.0" } it "does not change the lock" do - expect { ruby! "require 'bundler/setup'" }.not_to change { lockfile } + expect { ruby! "require '#{lib}/bundler/setup'" }.not_to change { lockfile } end end end @@ -1173,7 +1173,7 @@ end it "does not load Psych" do gemfile "" ruby <<-RUBY - require 'bundler/setup' + require '#{lib}/bundler/setup' puts defined?(Psych::VERSION) ? Psych::VERSION : "undefined" require 'psych' puts Psych::VERSION @@ -1186,7 +1186,7 @@ end it "does not load openssl" do install_gemfile! "" ruby! <<-RUBY - require "bundler/setup" + require "#{lib}/bundler/setup" puts defined?(OpenSSL) || "undefined" require "openssl" puts defined?(OpenSSL) || "undefined" @@ -1240,7 +1240,7 @@ end it "activates no gems with -rbundler/setup" do install_gemfile! "" - ruby! code, :env => { :RUBYOPT => activation_warning_hack_rubyopt + " -rbundler/setup" } + ruby! code, :env => { :RUBYOPT => activation_warning_hack_rubyopt + " -r#{lib}/bundler/setup" } expect(out).to eq("{}") end @@ -1315,7 +1315,7 @@ end G ruby! <<-RUBY - require "bundler/setup" + require "#{lib}/bundler/setup" Object.new.gem "rack" puts Gem.loaded_specs["rack"].full_name RUBY @@ -1330,7 +1330,7 @@ end G ruby <<-RUBY - require "bundler/setup" + require "#{lib}/bundler/setup" Object.new.gem "rack" puts "FAIL" RUBY @@ -1346,7 +1346,7 @@ end G ruby <<-RUBY - require "bundler/setup" + require "#{lib}/bundler/setup" Object.new.require "rack" puts "FAIL" RUBY diff --git a/spec/bundler/runtime/with_unbundled_env_spec.rb b/spec/bundler/runtime/with_unbundled_env_spec.rb index 30e8518043..62a9e40881 100644 --- a/spec/bundler/runtime/with_unbundled_env_spec.rb +++ b/spec/bundler/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 @@ -75,7 +75,7 @@ RSpec.describe "Bundler.with_env helpers" do it "should remove '-rbundler/setup' from RUBYOPT" do code = "print #{modified_env}['RUBYOPT']" ENV["RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}" - bundle_exec_ruby! code.dump + bundle_exec_ruby! code.dump, :env => { "BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM" => "true" } expect(last_command.stdboth).not_to include("-rbundler/setup") end diff --git a/spec/bundler/support/artifice/endpoint.rb b/spec/bundler/support/artifice/endpoint.rb index 0176059e87..966681f8d8 100644 --- a/spec/bundler/support/artifice/endpoint.rb +++ b/spec/bundler/support/artifice/endpoint.rb @@ -44,7 +44,7 @@ class Endpoint < Sinatra::Base def dependencies_for(gem_names, gem_repo = GEM_REPO) return [] if gem_names.nil? || gem_names.empty? - require "bundler" + require "#{Spec::Path.lib}/bundler" Bundler::Deprecate.skip_during do all_specs = %w[specs.4.8 prerelease_specs.4.8].map do |filename| Marshal.load(File.open(gem_repo.join(filename)).read) diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb index 5e6acdc783..c8f78a34a1 100644 --- a/spec/bundler/support/hax.rb +++ b/spec/bundler/support/hax.rb @@ -11,7 +11,8 @@ module Gem end @platforms = [Gem::Platform::RUBY, Gem::Platform.local] - if defined?(@path_to_default_spec_map) && !ENV["BUNDLER_SPEC_KEEP_DEFAULT_BUNDLER_GEM"] + # We only need this hack for rubygems versions without the BundlerVersionFinder + 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 diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index 9cd468dfa1..f069911f65 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -77,7 +77,7 @@ module Spec def run(cmd, *args) opts = args.last.is_a?(Hash) ? args.pop : {} groups = args.map(&:inspect).join(", ") - setup = "require 'bundler' ; Bundler.setup(#{groups})\n" + setup = "require '#{lib}/bundler' ; Bundler.setup(#{groups})\n" ruby(setup + cmd, opts) end bang :run