diff options
author | Bundlerbot <bot@bundler.io> | 2019-11-11 16:51:13 +0000 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-11-11 23:17:08 +0100 |
commit | db79526704d76fc69027f94332a811387cf483e2 (patch) | |
tree | 5bce1d9ad0baa4a93ed4df7d60a7c47c963fde08 /spec | |
parent | 27ae25003bb410c42d313a6e2b216b94495bebeb (diff) | |
download | bundler-db79526704d76fc69027f94332a811387cf483e2.tar.gz |
Merge #7434
7434: More lazy loading and relative requires r=deivid-rodriguez a=deivid-rodriguez
### What was the end-user problem that led to this PR?
The problem was that testing the latest version of bundler as a vendored copy inside rubygems surfaced some more issues about requiring the wrong code, or activating default gems too early.
### What was your diagnosis of the problem?
My diagnosis was that we should follow similar techniques I've used in other PRs: delay as much as possible requiring default gems, and don't rely on the LOAD_PATH for internal requires.
### What is your fix for the problem, implemented in this PR?
My fix does just that, and also removes a bunch of `require`'s that were not necessary at all.
Co-authored-by: David RodrÃguez <deivid.rodriguez@riseup.net>
(cherry picked from commit 147b9aa079f531ba5bf216d6d694fce5d36cfbfc)
Diffstat (limited to 'spec')
-rw-r--r-- | spec/install/binstubs_spec.rb | 1 | ||||
-rw-r--r-- | spec/lock/lockfile_spec.rb | 2 | ||||
-rw-r--r-- | spec/other/major_deprecation_spec.rb | 4 | ||||
-rw-r--r-- | spec/other/platform_spec.rb | 4 | ||||
-rw-r--r-- | spec/runtime/inline_spec.rb | 2 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 4 | ||||
-rw-r--r-- | spec/support/hax.rb | 6 | ||||
-rw-r--r-- | spec/support/matchers.rb | 3 | ||||
-rw-r--r-- | spec/support/rubygems_ext.rb | 3 |
9 files changed, 11 insertions, 18 deletions
diff --git a/spec/install/binstubs_spec.rb b/spec/install/binstubs_spec.rb index e7aa577077..78ee893b81 100644 --- a/spec/install/binstubs_spec.rb +++ b/spec/install/binstubs_spec.rb @@ -7,7 +7,6 @@ RSpec.describe "bundle install" do it "overrides Gem.bindir" do expect(Pathname.new("/usr/bin")).not_to be_writable unless Process.euid == 0 gemfile <<-G - require 'rubygems' def Gem.bindir; "/usr/bin"; end source "#{file_uri_for(gem_repo1)}" gem "rack" diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index e291fb7917..ddab4831a5 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -1418,7 +1418,6 @@ RSpec.describe "the lockfile format" do it "preserves Gemfile.lock \\n line endings" do expect do ruby <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup RUBY @@ -1432,7 +1431,6 @@ RSpec.describe "the lockfile format" do expect do ruby <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup RUBY diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index 57b68fdb97..f743bccb92 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -356,9 +356,7 @@ RSpec.describe "major deprecations" do G ruby <<-RUBY - require 'rubygems' - require 'bundler' - require 'bundler/vendored_thor' + require '#{lib_dir}/bundler' Bundler.setup Bundler.setup diff --git a/spec/other/platform_spec.rb b/spec/other/platform_spec.rb index 4feec14d76..8b02505ad8 100644 --- a/spec/other/platform_spec.rb +++ b/spec/other/platform_spec.rb @@ -1086,7 +1086,6 @@ G FileUtils.rm(bundled_app("Gemfile.lock")) ruby <<-R - require 'rubygems' require 'bundler/setup' R @@ -1106,7 +1105,6 @@ G FileUtils.rm(bundled_app("Gemfile.lock")) ruby <<-R - require 'rubygems' require 'bundler/setup' R @@ -1127,7 +1125,6 @@ G FileUtils.rm(bundled_app("Gemfile.lock")) ruby <<-R - require 'rubygems' require 'bundler/setup' R @@ -1148,7 +1145,6 @@ G FileUtils.rm(bundled_app("Gemfile.lock")) ruby <<-R - require 'rubygems' require 'bundler/setup' R diff --git a/spec/runtime/inline_spec.rb b/spec/runtime/inline_spec.rb index e5569fec94..06be2ef83d 100644 --- a/spec/runtime/inline_spec.rb +++ b/spec/runtime/inline_spec.rb @@ -115,7 +115,7 @@ RSpec.describe "bundler/inline#gemfile" do it "has an option for quiet installation" do script <<-RUBY, :artifice => "endpoint" - require 'bundler' + require '#{lib_dir}/bundler/inline' gemfile(true, :quiet => true) do source "https://notaserver.com" diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 72ad06a43a..4a754945b7 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -985,9 +985,7 @@ end build_git "bar", :gemspec => false do |s| s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0') s.write "bar.gemspec", <<-G - lib = File.expand_path('../lib/', __FILE__) - $:.unshift lib unless $:.include?(lib) - require 'bar/version' + require_relative 'lib/bar/version' Gem::Specification.new do |s| s.name = 'bar' diff --git a/spec/support/hax.rb b/spec/support/hax.rb index 3e1ece2f0a..c18470acd2 100644 --- a/spec/support/hax.rb +++ b/spec/support/hax.rb @@ -28,7 +28,8 @@ module Gem end if ENV["BUNDLER_SPEC_VERSION"] - require "bundler/version" + require_relative "path" + require "#{Spec::Path.lib_dir}/bundler/version" module Bundler remove_const(:VERSION) if const_defined?(:VERSION) @@ -37,7 +38,8 @@ if ENV["BUNDLER_SPEC_VERSION"] end if ENV["BUNDLER_SPEC_WINDOWS"] == "true" - require "bundler/constants" + require_relative "path" + require "#{Spec::Path.lib_dir}/bundler/constants" module Bundler remove_const :WINDOWS if defined?(WINDOWS) diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 69d3be4a3d..e1a08a30cc 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -128,9 +128,10 @@ module Spec groups << opts @errors = names.map do |name| name, version, platform = name.split(/\s+/) + require_path = name == "bundler" ? "#{lib_dir}/bundler" : name version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name) begin - run! "require '#{name}.rb'; puts #{version_const}", *groups + run! "require '#{require_path}.rb'; puts #{version_const}", *groups rescue StandardError => e next "#{name} is not installed:\n#{indent(e)}" end diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index 1093362d81..8c5dff880b 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require_relative "path" -require "fileutils" module Spec module Rubygems @@ -50,6 +49,8 @@ module Spec end def setup + require "fileutils" + Gem.clear_paths ENV["BUNDLE_PATH"] = nil |