1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[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
This commit is contained in:
David Rodríguez 2019-07-23 18:44:21 +02:00 committed by Hiroshi SHIBATA
parent 5a69a23afc
commit 4756c5f7e7
11 changed files with 48 additions and 48 deletions

View file

@ -42,8 +42,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
expect(changes_txt).to_not be_file expect(changes_txt).to_not be_file
end end
it "does not delete the bundler gem", :rubygems => ">= 2.6.2" do it "does not delete the bundler gem" do
ENV["BUNDLER_SPEC_KEEP_DEFAULT_BUNDLER_GEM"] = "true"
system_gems :bundler system_gems :bundler
bundle! "install" bundle! "install"
bundle! "pristine", :system_bundler => true bundle! "pristine", :system_bundler => true

View file

@ -333,7 +333,7 @@ RSpec.describe "bundle install with groups" do
G G
ruby <<-R ruby <<-R
require "bundler" require "#{lib}/bundler"
Bundler.setup :default Bundler.setup :default
Bundler.require :default Bundler.require :default
puts RACK puts RACK

View file

@ -25,9 +25,9 @@ RSpec.describe "double checking sources", :realworld => true, :sometimes => true
RUBY RUBY
cmd = <<-RUBY cmd = <<-RUBY
require "bundler" require "#{lib}/bundler"
require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump} require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump}
require "bundler/inline" require "#{lib}/bundler/inline"
gemfile(true) do gemfile(true) do
source "https://rubygems.org" source "https://rubygems.org"
gem "rails", path: "." gem "rails", path: "."

View file

@ -2,7 +2,7 @@
RSpec.describe "bundler/inline#gemfile" do RSpec.describe "bundler/inline#gemfile" do
def script(code, options = {}) 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.unshift File.expand_path("../../support/artifice/" + options.delete(:artifice) + ".rb", __FILE__) if options.key?(:artifice)
requires = requires.map {|r| "require '#{r}'" }.join("\n") requires = requires.map {|r| "require '#{r}'" }.join("\n")
@out = ruby("#{requires}\n\n" + code, options) @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 it "lets me use my own ui object" do
script <<-RUBY, :artifice => "endpoint" script <<-RUBY, :artifice => "endpoint"
require 'bundler' require '#{lib}/bundler'
class MyBundlerUI < Bundler::UI::Silent class MyBundlerUI < Bundler::UI::Silent
def confirm(msg, newline = nil) def confirm(msg, newline = nil)
puts "CONFIRMED!" puts "CONFIRMED!"
@ -140,7 +140,7 @@ RSpec.describe "bundler/inline#gemfile" do
it "does not mutate the option argument" do it "does not mutate the option argument" do
script <<-RUBY script <<-RUBY
require 'bundler' require '#{lib}/bundler'
options = { :ui => Bundler::UI::Shell.new } options = { :ui => Bundler::UI::Shell.new }
gemfile(false, options) do gemfile(false, options) do
path "#{lib_path}" do path "#{lib_path}" do

View file

@ -80,7 +80,7 @@ RSpec.describe "Bundler.load" do
G G
ruby! <<-RUBY ruby! <<-RUBY
require "bundler" require "#{lib}/bundler"
Bundler.setup :default Bundler.setup :default
Bundler.require :default Bundler.require :default
puts RACK puts RACK

View file

@ -193,7 +193,7 @@ RSpec.describe "Bundler.require" do
G G
cmd = <<-RUBY cmd = <<-RUBY
require 'bundler' require '#{lib}/bundler'
Bundler.require Bundler.require
RUBY RUBY
ruby(cmd) ruby(cmd)

View file

@ -12,7 +12,7 @@ RSpec.describe "Bundler.setup" do
G G
ruby <<-RUBY ruby <<-RUBY
require 'bundler' require '#{lib}/bundler'
Bundler.setup Bundler.setup
require 'rack' require 'rack'
@ -34,7 +34,7 @@ RSpec.describe "Bundler.setup" do
it "doesn't make all groups available" do it "doesn't make all groups available" do
ruby <<-RUBY ruby <<-RUBY
require 'bundler' require '#{lib}/bundler'
Bundler.setup(:default) Bundler.setup(:default)
begin begin
@ -49,7 +49,7 @@ RSpec.describe "Bundler.setup" do
it "accepts string for group name" do it "accepts string for group name" do
ruby <<-RUBY ruby <<-RUBY
require 'bundler' require '#{lib}/bundler'
Bundler.setup(:default, 'test') Bundler.setup(:default, 'test')
require 'rack' require 'rack'
@ -61,7 +61,7 @@ RSpec.describe "Bundler.setup" do
it "leaves all groups available if they were already" do it "leaves all groups available if they were already" do
ruby <<-RUBY ruby <<-RUBY
require 'bundler' require '#{lib}/bundler'
Bundler.setup Bundler.setup
Bundler.setup(:default) Bundler.setup(:default)
@ -74,7 +74,7 @@ RSpec.describe "Bundler.setup" do
it "leaves :default available if setup is called twice" do it "leaves :default available if setup is called twice" do
ruby <<-RUBY ruby <<-RUBY
require 'bundler' require '#{lib}/bundler'
Bundler.setup(:default) Bundler.setup(:default)
Bundler.setup(:default, :test) Bundler.setup(:default, :test)
@ -91,7 +91,7 @@ RSpec.describe "Bundler.setup" do
it "handles multiple non-additive invocations" do it "handles multiple non-additive invocations" do
ruby <<-RUBY ruby <<-RUBY
require 'bundler' require '#{lib}/bundler'
Bundler.setup(:default, :test) Bundler.setup(:default, :test)
Bundler.setup(:default) Bundler.setup(:default)
require 'rack' require 'rack'
@ -122,7 +122,7 @@ RSpec.describe "Bundler.setup" do
ENV["RUBYLIB"] = "rubylib_dir" ENV["RUBYLIB"] = "rubylib_dir"
ruby <<-RUBY ruby <<-RUBY
require 'bundler' require '#{lib}/bundler'
Bundler.setup Bundler.setup
puts $LOAD_PATH puts $LOAD_PATH
RUBY RUBY
@ -144,7 +144,7 @@ RSpec.describe "Bundler.setup" do
G G
ruby! <<-RUBY ruby! <<-RUBY
require 'bundler' require '#{lib}/bundler'
Bundler.setup Bundler.setup
puts $LOAD_PATH puts $LOAD_PATH
RUBY RUBY
@ -172,7 +172,7 @@ RSpec.describe "Bundler.setup" do
G G
ruby! <<-RUBY ruby! <<-RUBY
require 'bundler/setup' require '#{lib}/bundler/setup'
puts $LOAD_PATH puts $LOAD_PATH
RUBY RUBY
@ -193,7 +193,7 @@ RSpec.describe "Bundler.setup" do
G G
ruby <<-R ruby <<-R
require 'bundler' require '#{lib}/bundler'
begin begin
Bundler.setup Bundler.setup
@ -213,7 +213,7 @@ RSpec.describe "Bundler.setup" do
G G
ruby <<-R ruby <<-R
require 'bundler' require '#{lib}/bundler'
Bundler.setup Bundler.setup
R R
@ -236,7 +236,7 @@ RSpec.describe "Bundler.setup" do
G G
ruby <<-R ruby <<-R
require 'bundler' require '#{lib}/bundler'
Bundler.setup Bundler.setup
R R
@ -289,7 +289,7 @@ RSpec.describe "Bundler.setup" do
ENV["BUNDLE_GEMFILE"] = "Gemfile" ENV["BUNDLE_GEMFILE"] = "Gemfile"
ruby <<-R ruby <<-R
require 'bundler' require '#{lib}/bundler'
begin begin
Bundler.setup Bundler.setup
@ -444,7 +444,7 @@ RSpec.describe "Bundler.setup" do
break_git! break_git!
ruby <<-R ruby <<-R
require 'bundler' require '#{lib}/bundler'
begin begin
Bundler.setup Bundler.setup
@ -465,7 +465,7 @@ RSpec.describe "Bundler.setup" do
break_git! break_git!
ruby <<-R ruby <<-R
require "bundler" require "#{lib}/bundler"
begin begin
Bundler.setup Bundler.setup
@ -774,7 +774,7 @@ end
s.class.send(:define_method, :build_extensions) { nil } s.class.send(:define_method, :build_extensions) { nil }
end end
require 'bundler' require '#{lib}/bundler'
gem '#{gem_name}' gem '#{gem_name}'
puts $LOAD_PATH.count {|path| path =~ /#{gem_name}/} >= 2 puts $LOAD_PATH.count {|path| path =~ /#{gem_name}/} >= 2
@ -1028,7 +1028,7 @@ end
bundle "install" bundle "install"
ruby <<-RUBY ruby <<-RUBY
require 'bundler' require '#{lib}/bundler'
def Bundler.require(path) def Bundler.require(path)
raise "LOSE" raise "LOSE"
end end
@ -1083,7 +1083,7 @@ end
context "is not present" do context "is not present" do
it "does not change the lock" do it "does not change the lock" do
lockfile lock_with(nil) lockfile lock_with(nil)
ruby "require 'bundler/setup'" ruby "require '#{lib}/bundler/setup'"
lockfile_should_be lock_with(nil) lockfile_should_be lock_with(nil)
end end
end end
@ -1091,7 +1091,7 @@ end
context "is newer" do context "is newer" do
it "does not change the lock or warn" do it "does not change the lock or warn" do
lockfile lock_with(Bundler::VERSION.succ) lockfile lock_with(Bundler::VERSION.succ)
ruby "require 'bundler/setup'" ruby "require '#{lib}/bundler/setup'"
expect(out).to eq("") expect(out).to eq("")
expect(err).to eq("") expect(err).to eq("")
lockfile_should_be lock_with(Bundler::VERSION.succ) lockfile_should_be lock_with(Bundler::VERSION.succ)
@ -1101,7 +1101,7 @@ end
context "is older" do context "is older" do
it "does not change the lock" do it "does not change the lock" do
lockfile lock_with("1.10.1") lockfile lock_with("1.10.1")
ruby "require 'bundler/setup'" ruby "require '#{lib}/bundler/setup'"
lockfile_should_be lock_with("1.10.1") lockfile_should_be lock_with("1.10.1")
end end
end end
@ -1148,14 +1148,14 @@ end
context "is not present" do context "is not present" do
it "does not change the lock" 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
end end
context "is newer" do context "is newer" do
let(:ruby_version) { "5.5.5" } let(:ruby_version) { "5.5.5" }
it "does not change the lock or warn" do 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(out).to eq("")
expect(err).to eq("") expect(err).to eq("")
end end
@ -1164,7 +1164,7 @@ end
context "is older" do context "is older" do
let(:ruby_version) { "1.0.0" } let(:ruby_version) { "1.0.0" }
it "does not change the lock" 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
end end
end end
@ -1173,7 +1173,7 @@ end
it "does not load Psych" do it "does not load Psych" do
gemfile "" gemfile ""
ruby <<-RUBY ruby <<-RUBY
require 'bundler/setup' require '#{lib}/bundler/setup'
puts defined?(Psych::VERSION) ? Psych::VERSION : "undefined" puts defined?(Psych::VERSION) ? Psych::VERSION : "undefined"
require 'psych' require 'psych'
puts Psych::VERSION puts Psych::VERSION
@ -1186,7 +1186,7 @@ end
it "does not load openssl" do it "does not load openssl" do
install_gemfile! "" install_gemfile! ""
ruby! <<-RUBY ruby! <<-RUBY
require "bundler/setup" require "#{lib}/bundler/setup"
puts defined?(OpenSSL) || "undefined" puts defined?(OpenSSL) || "undefined"
require "openssl" require "openssl"
puts defined?(OpenSSL) || "undefined" puts defined?(OpenSSL) || "undefined"
@ -1240,7 +1240,7 @@ end
it "activates no gems with -rbundler/setup" do it "activates no gems with -rbundler/setup" do
install_gemfile! "" 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("{}") expect(out).to eq("{}")
end end
@ -1315,7 +1315,7 @@ end
G G
ruby! <<-RUBY ruby! <<-RUBY
require "bundler/setup" require "#{lib}/bundler/setup"
Object.new.gem "rack" Object.new.gem "rack"
puts Gem.loaded_specs["rack"].full_name puts Gem.loaded_specs["rack"].full_name
RUBY RUBY
@ -1330,7 +1330,7 @@ end
G G
ruby <<-RUBY ruby <<-RUBY
require "bundler/setup" require "#{lib}/bundler/setup"
Object.new.gem "rack" Object.new.gem "rack"
puts "FAIL" puts "FAIL"
RUBY RUBY
@ -1346,7 +1346,7 @@ end
G G
ruby <<-RUBY ruby <<-RUBY
require "bundler/setup" require "#{lib}/bundler/setup"
Object.new.require "rack" Object.new.require "rack"
puts "FAIL" puts "FAIL"
RUBY RUBY

View file

@ -1,15 +1,15 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe "Bundler.with_env helpers" do RSpec.describe "Bundler.with_env helpers" do
def bundle_exec_ruby!(code) def bundle_exec_ruby!(code, options = {})
build_bundler_context build_bundler_context options
bundle! "exec '#{Gem.ruby}' -e #{code}" bundle! "exec '#{Gem.ruby}' -e #{code}", options
end end
def build_bundler_context def build_bundler_context(options = {})
bundle "config set path vendor/bundle" bundle "config set path vendor/bundle"
gemfile "" gemfile ""
bundle "install" bundle "install", options
end end
describe "Bundler.original_env" do describe "Bundler.original_env" do
@ -75,7 +75,7 @@ RSpec.describe "Bundler.with_env helpers" do
it "should remove '-rbundler/setup' from RUBYOPT" do it "should remove '-rbundler/setup' from RUBYOPT" do
code = "print #{modified_env}['RUBYOPT']" code = "print #{modified_env}['RUBYOPT']"
ENV["RUBYOPT"] = "-W2 -rbundler/setup #{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") expect(last_command.stdboth).not_to include("-rbundler/setup")
end end

View file

@ -44,7 +44,7 @@ class Endpoint < Sinatra::Base
def dependencies_for(gem_names, gem_repo = GEM_REPO) def dependencies_for(gem_names, gem_repo = GEM_REPO)
return [] if gem_names.nil? || gem_names.empty? return [] if gem_names.nil? || gem_names.empty?
require "bundler" require "#{Spec::Path.lib}/bundler"
Bundler::Deprecate.skip_during do Bundler::Deprecate.skip_during do
all_specs = %w[specs.4.8 prerelease_specs.4.8].map do |filename| all_specs = %w[specs.4.8 prerelease_specs.4.8].map do |filename|
Marshal.load(File.open(gem_repo.join(filename)).read) Marshal.load(File.open(gem_repo.join(filename)).read)

View file

@ -11,7 +11,8 @@ module Gem
end end
@platforms = [Gem::Platform::RUBY, Gem::Platform.local] @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| @path_to_default_spec_map.delete_if do |_path, spec|
spec.name == "bundler" spec.name == "bundler"
end end

View file

@ -77,7 +77,7 @@ module Spec
def run(cmd, *args) def run(cmd, *args)
opts = args.last.is_a?(Hash) ? args.pop : {} opts = args.last.is_a?(Hash) ? args.pop : {}
groups = args.map(&:inspect).join(", ") groups = args.map(&:inspect).join(", ")
setup = "require 'bundler' ; Bundler.setup(#{groups})\n" setup = "require '#{lib}/bundler' ; Bundler.setup(#{groups})\n"
ruby(setup + cmd, opts) ruby(setup + cmd, opts)
end end
bang :run bang :run