summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-12-01 16:27:19 +0000
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2019-12-13 20:07:20 +0100
commit144b55c75d0e2e2ba0a73bce7ba9801d74970a93 (patch)
tree8ddc58de72872efff4be587b129ba879c8712172
parent4e4ea8f212fc2b052341606b54f3bd97497163b4 (diff)
downloadbundler-144b55c75d0e2e2ba0a73bce7ba9801d74970a93.tar.gz
Merge #7464
7464: Improve rubygems switcher r=deivid-rodriguez a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was we have some code in our tests to make sure that the `ENV["RGV"]` variable we use to set the rubygems version we want to test bundler against is always respected, including every subprocess our tests start. However: * The code was overly complicated. * It didn't support custom branches, for example, `RGV=lazily_load_uri`. This is a feature I find very useful when a PR you're working on also need some changes in the rubygems side, like it happened to me at #7460. ### What was your diagnosis of the problem? My diagnosis was that all the code needs to do is: * Set up the location of the rubygems code we'll test bundler against, be it a path, a branch, or a released version. * Modify `RUBYOPT` to include that location in the LOAD_PATH, so that `rubygems` is always loaded from there instead of the system's version. ### What is your fix for the problem, implemented in this PR? My fix is to do just that, remove all the stuff that wasn't needed, and do a bit of renaming to improve readability. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net> (cherry picked from commit 0cb51921d238f330c91673428b53f523016cdd01)
-rw-r--r--spec/rubygems/rubygems.rb9
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/support/rubygems_ext.rb4
-rw-r--r--spec/support/rubygems_version_manager.rb74
4 files changed, 29 insertions, 60 deletions
diff --git a/spec/rubygems/rubygems.rb b/spec/rubygems/rubygems.rb
deleted file mode 100644
index 6fa63013bf..0000000000
--- a/spec/rubygems/rubygems.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# frozen_string_literal: true
-
-require_relative "../support/rubygems_version_manager"
-
-RubygemsVersionManager.new(ENV["RGV"]).switch
-
-$:.delete("#{Spec::Path.spec_dir}/rubygems")
-
-require "rubygems"
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 9702ab71f5..ba21d22fbd 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -82,7 +82,7 @@ RSpec.configure do |config|
config.before :suite do
require_relative "support/rubygems_ext"
Spec::Rubygems.setup
- ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{Spec::Path.spec_dir}/rubygems -r#{Spec::Path.spec_dir}/support/hax.rb"
+ ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb"
ENV["BUNDLE_SPEC_RUN"] = "true"
ENV["BUNDLE_USER_CONFIG"] = ENV["BUNDLE_USER_CACHE"] = ENV["BUNDLE_USER_PLUGIN"] = nil
ENV["GEMRC"] = nil
diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb
index 5bfcac5ac4..3914465371 100644
--- a/spec/support/rubygems_ext.rb
+++ b/spec/support/rubygems_ext.rb
@@ -39,7 +39,9 @@ module Spec
end
def gem_load(gem_name, bin_container)
- require_relative "../rubygems/rubygems"
+ require_relative "rubygems_version_manager"
+ RubygemsVersionManager.new(ENV["RGV"]).switch
+
gem_load_and_activate(gem_name, bin_container)
end
diff --git a/spec/support/rubygems_version_manager.rb b/spec/support/rubygems_version_manager.rb
index 356d391c08..854bce890d 100644
--- a/spec/support/rubygems_version_manager.rb
+++ b/spec/support/rubygems_version_manager.rb
@@ -8,27 +8,25 @@ class RubygemsVersionManager
include Spec::Helpers
include Spec::Path
- def initialize(env_version)
- @env_version = env_version
+ def initialize(source)
+ @source = source
end
def switch
return if use_system?
- unrequire_rubygems_if_needed
-
switch_local_copy_if_needed
- prepare_environment
+ reexec_if_needed
end
private
def use_system?
- @env_version.nil?
+ @source.nil?
end
- def unrequire_rubygems_if_needed
+ def reexec_if_needed
return unless rubygems_unrequire_needed?
require "rbconfig"
@@ -37,7 +35,8 @@ private
ruby << RbConfig::CONFIG["EXEEXT"]
cmd = [ruby, $0, *ARGV].compact
- cmd[1, 0] = "--disable-gems"
+
+ ENV["RUBYOPT"] = "-I#{local_copy_path.join("lib")} #{ENV["RUBYOPT"]}"
exec(ENV, *cmd)
end
@@ -47,35 +46,28 @@ private
Dir.chdir(local_copy_path) do
sys_exec!("git remote update")
- sys_exec!("git checkout #{target_tag_version} --quiet")
+ sys_exec!("git checkout #{target_tag} --quiet")
end
- end
- def prepare_environment
- $:.unshift File.expand_path("lib", local_copy_path)
+ ENV["RGV"] = local_copy_path.to_s
end
def rubygems_unrequire_needed?
- defined?(Gem::VERSION) && Gem::VERSION != target_gem_version
+ !$LOADED_FEATURES.include?(local_copy_path.join("lib/rubygems.rb").to_s)
end
def local_copy_switch_needed?
- !env_version_is_path? && target_gem_version != local_copy_version
- end
-
- def target_gem_version
- @target_gem_version ||= resolve_target_gem_version
+ !source_is_path? && target_tag != local_copy_tag
end
- def target_tag_version
- @target_tag_version ||= resolve_target_tag_version
+ def target_tag
+ @target_tag ||= resolve_target_tag
end
- def local_copy_version
- gemspec_contents = File.read(local_copy_path.join("lib/rubygems.rb"))
- version_regexp = /VERSION = ["'](.*)["']/
-
- version_regexp.match(gemspec_contents)[1]
+ def local_copy_tag
+ Dir.chdir(local_copy_path) do
+ sys_exec!("git rev-parse --abbrev-ref HEAD")
+ end
end
def local_copy_path
@@ -83,7 +75,7 @@ private
end
def resolve_local_copy_path
- return expanded_env_version if env_version_is_path?
+ return expanded_source if source_is_path?
rubygems_path = root.join("tmp/rubygems")
@@ -95,33 +87,17 @@ private
rubygems_path
end
- def env_version_is_path?
- expanded_env_version.directory?
+ def source_is_path?
+ expanded_source.directory?
end
- def expanded_env_version
- @expanded_env_version ||= Pathname.new(@env_version).expand_path(root)
+ def expanded_source
+ @expanded_source ||= Pathname.new(@source).expand_path(root)
end
- def resolve_target_tag_version
- return "v#{@env_version}" if @env_version.match(/^\d/)
-
- return "master" if @env_version == master_gem_version
-
- @env_version
- end
-
- def resolve_target_gem_version
- return local_copy_version if env_version_is_path?
-
- return @env_version[1..-1] if @env_version.match(/^v/)
-
- return master_gem_version if @env_version == "master"
-
- @env_version
- end
+ def resolve_target_tag
+ return "v#{@source}" if @source.match(/^\d/)
- def master_gem_version
- "3.1.0.pre1"
+ @source
end
end