[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
This commit is contained in:
David Rodríguez 2021-07-22 11:35:15 +02:00 committed by Hiroshi SHIBATA
parent 90899c50c2
commit 4271f4aea5
No known key found for this signature in database
GPG Key ID: F9CF13417264FAC2
2 changed files with 17 additions and 10 deletions

View File

@ -60,16 +60,16 @@ m = Module.new do
Regexp.last_match(1) Regexp.last_match(1)
end end
def bundler_version def bundler_requirement
@bundler_version ||= @bundler_requirement ||=
env_var_version || cli_arg_version || env_var_version || cli_arg_version ||
lockfile_version bundler_requirement_for(lockfile_version)
end end
def bundler_requirement def bundler_requirement_for(version)
return "#{Gem::Requirement.default}.a" unless bundler_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 requirement = bundler_gem_version.approximate_recommendation

View File

@ -140,8 +140,15 @@ RSpec.describe "bundle binstubs <gem>" do
it "runs the correct version of bundler" do it "runs the correct version of bundler" do
sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "999.999.999" }, :raise_on_error => false sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "999.999.999" }, :raise_on_error => false
expect(exitstatus).to eq(42) expect(exitstatus).to eq(42)
expect(err).to include("Activating bundler (~> 999.999) failed:"). 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'`") 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
end end
@ -215,8 +222,8 @@ RSpec.describe "bundle binstubs <gem>" do
it "calls through to the explicit bundler version" do it "calls through to the explicit bundler version" do
sys_exec "bin/bundle update --bundler=999.999.999", :raise_on_error => false sys_exec "bin/bundle update --bundler=999.999.999", :raise_on_error => false
expect(exitstatus).to eq(42) expect(exitstatus).to eq(42)
expect(err).to include("Activating bundler (~> 999.999) failed:"). 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'`") and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`")
end end
end end