1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[bundler/bundler] Use a consistent requirement in binstub

https://github.com/bundler/bundler/commit/50ccdb32c2
This commit is contained in:
David Rodríguez 2019-07-16 11:52:14 +02:00 committed by Hiroshi SHIBATA
parent bb6b9b4929
commit a1c69991a5
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 21 additions and 10 deletions

View file

@ -31,7 +31,7 @@ m = Module.new do
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1 || ">= 0.a"
bundler_version = $1
update_index = i
end
bundler_version
@ -63,27 +63,30 @@ m = Module.new do
def bundler_version
@bundler_version ||=
env_var_version || cli_arg_version ||
lockfile_version || "#{Gem::Requirement.default}.a"
lockfile_version
end
def bundler_requirement
return "#{Gem::Requirement.default}.a" unless bundler_version
Gem::Version.new(bundler_version).approximate_recommendation
end
def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile
activate_bundler(bundler_version)
activate_bundler(bundler_requirement)
end
def activate_bundler(bundler_version)
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
bundler_version = "< 2"
end
def activate_bundler(bundler_requirement)
gem_error = activation_error_handling do
gem "bundler", bundler_version
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
exit 42
end

View file

@ -149,7 +149,7 @@ RSpec.describe "bundle binstubs <gem>" do
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 when the version is older" do
it "runs the correct version of bundler when the version is older and a different major" do
simulate_bundler_version "55"
lockfile lockfile.gsub(system_bundler_version, "44.0")
sys_exec "#{bundled_app("bin/bundle")} install"
@ -158,6 +158,14 @@ RSpec.describe "bundle binstubs <gem>" do
and include("To install the version of bundler this project requires, run `gem install bundler -v '44.0'`")
end
it "runs the available version of bundler when the version is older and the same major" do
simulate_bundler_version "55.1"
lockfile lockfile.gsub(system_bundler_version, "55.0")
sys_exec "#{bundled_app("bin/bundle")} install"
expect(exitstatus).not_to eq(42) if exitstatus
expect(err).not_to include("Activating bundler (55.0) failed:")
end
it "runs the correct version of bundler when the version is a pre-release" do
simulate_bundler_version "55"
lockfile lockfile.gsub(system_bundler_version, "2.12.0.a")