From 4271f4aea5a49775cb904beffeda8d0c37ddbe64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 22 Jul 2021 11:35:15 +0200 Subject: [PATCH] [rubygems/rubygems] Fix bundler binstub version selection To mimic built-in rubygems behaviour, only thing that should be approximated is the lockfile version. Other alternatives like `BUNDLER_VERSION` should be respected exactly. https://github.com/rubygems/rubygems/commit/dbd667d4bc --- lib/bundler/templates/Executable.bundler | 12 ++++++------ spec/bundler/commands/binstubs_spec.rb | 15 +++++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler index 69f26bb9c0..8009412ea2 100644 --- a/lib/bundler/templates/Executable.bundler +++ b/lib/bundler/templates/Executable.bundler @@ -60,16 +60,16 @@ m = Module.new do Regexp.last_match(1) end - def bundler_version - @bundler_version ||= + def bundler_requirement + @bundler_requirement ||= env_var_version || cli_arg_version || - lockfile_version + bundler_requirement_for(lockfile_version) end - def bundler_requirement - return "#{Gem::Requirement.default}.a" unless bundler_version + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version - bundler_gem_version = Gem::Version.new(bundler_version) + bundler_gem_version = Gem::Version.new(version) requirement = bundler_gem_version.approximate_recommendation diff --git a/spec/bundler/commands/binstubs_spec.rb b/spec/bundler/commands/binstubs_spec.rb index 3b177b32ea..2006485fca 100644 --- a/spec/bundler/commands/binstubs_spec.rb +++ b/spec/bundler/commands/binstubs_spec.rb @@ -140,8 +140,15 @@ RSpec.describe "bundle binstubs " do it "runs the correct version of bundler" do sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "999.999.999" }, :raise_on_error => false expect(exitstatus).to eq(42) - expect(err).to include("Activating bundler (~> 999.999) failed:"). - and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") + expect(err).to include("Activating bundler (999.999.999) failed:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`") + end + + it "runs the correct version of bundler even if a higher version is installed" do + system_gems "bundler-999.999.998", "bundler-999.999.999" + + sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "999.999.998", "DEBUG" => "1" }, :raise_on_error => false + expect(out).to include %(Using bundler 999.999.998\n) end end @@ -215,8 +222,8 @@ RSpec.describe "bundle binstubs " do it "calls through to the explicit bundler version" do sys_exec "bin/bundle update --bundler=999.999.999", :raise_on_error => false expect(exitstatus).to eq(42) - expect(err).to include("Activating bundler (~> 999.999) failed:"). - and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") + expect(err).to include("Activating bundler (999.999.999) failed:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`") end end