diff options
author | Bundlerbot <bot@bundler.io> | 2019-12-01 16:27:19 +0000 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-12-13 20:07:20 +0100 |
commit | 144b55c75d0e2e2ba0a73bce7ba9801d74970a93 (patch) | |
tree | 8ddc58de72872efff4be587b129ba879c8712172 /spec/support/rubygems_version_manager.rb | |
parent | 4e4ea8f212fc2b052341606b54f3bd97497163b4 (diff) | |
download | bundler-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)
Diffstat (limited to 'spec/support/rubygems_version_manager.rb')
-rw-r--r-- | spec/support/rubygems_version_manager.rb | 74 |
1 files changed, 25 insertions, 49 deletions
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 |