diff options
-rw-r--r-- | lib/bundler/templates/Executable.bundler | 20 | ||||
-rw-r--r-- | spec/commands/binstubs_spec.rb | 14 | ||||
-rw-r--r-- | spec/support/rubygems_ext.rb | 1 |
3 files changed, 24 insertions, 11 deletions
diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler index 085955c7a9..eeda90b584 100644 --- a/lib/bundler/templates/Executable.bundler +++ b/lib/bundler/templates/Executable.bundler @@ -24,9 +24,17 @@ m = Module.new do def cli_arg_version return unless invoked_as_script? # don't want to hijack other binstubs return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` - return unless update = ARGV.find {|a| a.start_with?("--bundler") } # must have a --bundler arg - return unless update =~ /--bundler(?:=(.+))?/ - $1 || ">= 0.a" + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 || ">= 0.a" + update_index = i + end + bundler_version end def gemfile @@ -62,10 +70,14 @@ m = Module.new do def load_bundler! ENV["BUNDLE_GEMFILE"] ||= gemfile - activate_bundler(bundler_version) + # must dup string for RG < 1.8 compatibility + activate_bundler(bundler_version.dup) 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 gem_error = activation_error_handling do gem "bundler", bundler_version end diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb index fa44928625..decf361d1d 100644 --- a/spec/commands/binstubs_spec.rb +++ b/spec/commands/binstubs_spec.rb @@ -107,19 +107,21 @@ RSpec.describe "bundle binstubs <gem>" do end it "runs the correct version of bundler when the version is older" do - lockfile lockfile.gsub(system_bundler_version, "1.0") + simulate_bundler_version "55" + lockfile lockfile.gsub(system_bundler_version, "44.0") sys_exec "#{bundled_app("bin/bundle")} install" expect(exitstatus).to eq(42) if exitstatus - expect(last_command.stderr).to include("Activating bundler (1.0) failed:"). - and include("To install the version of bundler this project requires, run `gem install bundler -v '1.0'`") + expect(last_command.stderr).to include("Activating bundler (44.0) failed:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '44.0'`") end it "runs the correct version of bundler when the version is a pre-release" do - lockfile lockfile.gsub(system_bundler_version, "1.12.0.a") + simulate_bundler_version "55" + lockfile lockfile.gsub(system_bundler_version, "2.12.0.a") sys_exec "#{bundled_app("bin/bundle")} install" expect(exitstatus).to eq(42) if exitstatus - expect(last_command.stderr).to include("Activating bundler (1.12.0.a) failed:"). - and include("To install the version of bundler this project requires, run `gem install bundler -v '1.12.0.a'`") + expect(last_command.stderr).to include("Activating bundler (2.12.0.a) failed:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '2.12.0.a'`") end end diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index 3b8cd0cf62..3f88215e43 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -22,7 +22,6 @@ module Spec "rake" => "10.0.2", # 3.0.0 breaks 1.9.2 specs "builder" => "2.1.2", - "bundler" => "1.12.0", } # ruby-graphviz is used by the viz tests deps["ruby-graphviz"] = nil if RUBY_VERSION >= "1.9.3" |