diff --git lib/rubygems.rb lib/rubygems.rb index cd7434ca87..f3671d9f2a 100644 --- lib/rubygems.rb +++ lib/rubygems.rb @@ -10,7 +10,7 @@ require 'thread' module Gem - VERSION = "2.7.6.1" + VERSION = "2.7.6.2" end # Must be first since it unloads the prelude from 1.9.2 @@ -270,12 +270,7 @@ def self.find_spec_for_exe name, exec_name, requirements return loaded if loaded && dep.matches_spec?(loaded) - find_specs = proc { dep.matching_specs(true) } - if dep.to_s == "bundler (>= 0.a)" - specs = Gem::BundlerVersionFinder.without_filtering(&find_specs) - else - specs = find_specs.call - end + specs = dep.matching_specs(true) specs = specs.find_all { |spec| spec.executables.include? exec_name diff --git lib/rubygems/bundler_version_finder.rb lib/rubygems/bundler_version_finder.rb index baca170840..ba25399d1e 100644 --- lib/rubygems/bundler_version_finder.rb +++ lib/rubygems/bundler_version_finder.rb @@ -1,12 +1,4 @@ module Gem::BundlerVersionFinder - @without_filtering = false - - def self.without_filtering - without_filtering, @without_filtering = true, @without_filtering - yield - ensure - @without_filtering = without_filtering - end def self.bundler_version version, _ = bundler_version_with_reason @@ -17,8 +9,6 @@ def self.bundler_version end def self.bundler_version_with_reason - return if @without_filtering - if v = ENV["BUNDLER_VERSION"] return [v, "`$BUNDLER_VERSION`"] end @@ -36,7 +26,7 @@ def self.missing_version_message return unless vr = bundler_version_with_reason <<-EOS Could not find 'bundler' (#{vr.first}) required by #{vr.last}. -To update to the lastest version installed on your system, run `bundle update --bundler`. +To update to the latest version installed on your system, run `bundle update --bundler`. To install the missing version, run `gem install bundler:#{vr.first}` EOS end @@ -44,20 +34,14 @@ def self.missing_version_message def self.compatible?(spec) return true unless spec.name == "bundler".freeze return true unless bundler_version = self.bundler_version - if bundler_version.segments.first >= 2 - spec.version == bundler_version - else # 1.x - spec.version.segments.first < 2 - end + + spec.version.segments.first == bundler_version.segments.first end def self.filter!(specs) return unless bundler_version = self.bundler_version - if bundler_version.segments.first >= 2 - specs.reject! { |spec| spec.version != bundler_version } - else # 1.x - specs.reject! { |spec| spec.version.segments.first >= 2} - end + + specs.reject! { |spec| spec.version.segments.first != bundler_version.segments.first } end def self.bundle_update_bundler_version diff --git test/rubygems/test_gem.rb test/rubygems/test_gem.rb index 693e5e0969..419497c75f 100644 --- test/rubygems/test_gem.rb +++ test/rubygems/test_gem.rb @@ -209,6 +209,41 @@ def test_activate_bin_path_resolves_eagerly assert_equal %w(a-1 b-2 c-1), loaded_spec_names end + def test_activate_bin_path_gives_proper_error_for_bundler + bundler = util_spec 'bundler', '2' do |s| + s.executables = ['bundle'] + end + + install_specs bundler + + File.open("Gemfile.lock", "w") do |f| + f.write <<-L.gsub(/ {8}/, "") + GEM + remote: https://rubygems.org/ + specs: + + PLATFORMS + ruby + + DEPENDENCIES + + BUNDLED WITH + 9999 + L + end + + File.open("Gemfile", "w") { |f| f.puts('source "https://rubygems.org"') } + + e = assert_raises Gem::GemNotFoundException do + load Gem.activate_bin_path("bundler", "bundle", ">= 0.a") + end + + assert_includes e.message, "Could not find 'bundler' (9999) required by your #{File.expand_path("Gemfile.lock")}." + assert_includes e.message, "To update to the latest version installed on your system, run `bundle update --bundler`." + assert_includes e.message, "To install the missing version, run `gem install bundler:9999`" + refute_includes e.message, "can't find gem bundler (>= 0.a) with executable bundle" + end + def test_self_bin_path_no_exec_name e = assert_raises ArgumentError do Gem.bin_path 'a' diff --git test/rubygems/test_gem_bundler_version_finder.rb test/rubygems/test_gem_bundler_version_finder.rb index 7dafe13033..3b63b89423 100644 --- test/rubygems/test_gem_bundler_version_finder.rb +++ test/rubygems/test_gem_bundler_version_finder.rb @@ -88,20 +88,21 @@ def test_compatible bvf.stub(:bundler_version, v("2.1.1.1")) do assert bvf.compatible?(util_spec("foo")) assert bvf.compatible?(util_spec("bundler", "2.1.1.1")) - refute bvf.compatible?(util_spec("bundler", "2.1.1.a")) + assert bvf.compatible?(util_spec("bundler", "2.1.1.a")) + assert bvf.compatible?(util_spec("bundler", "2.999")) refute bvf.compatible?(util_spec("bundler", "1.999")) - refute bvf.compatible?(util_spec("bundler", "2.999")) + refute bvf.compatible?(util_spec("bundler", "3.0.0")) end end def test_filter - versions = %w[1 1.0 1.0.1.1 2.a 3 3.0] + versions = %w[1 1.0 1.0.1.1 2 2.a 2.0 2.1.1 3 3.a 3.0 3.1.1] specs = versions.map { |v| util_spec("bundler", v) } - assert_equal %w[1 1.0 1.0.1.1 2.a 3 3.0], util_filter_specs(specs).map(&:version).map(&:to_s) + assert_equal %w[1 1.0 1.0.1.1 2 2.a 2.0 2.1.1 3 3.a 3.0 3.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) bvf.stub(:bundler_version, v("2.1.1.1")) do - assert_empty util_filter_specs(specs).map(&:version).map(&:to_s) + assert_equal %w[2 2.a 2.0 2.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) end bvf.stub(:bundler_version, v("1.1.1.1")) do assert_equal %w[1 1.0 1.0.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) @@ -110,10 +111,10 @@ def test_filter assert_equal %w[1 1.0 1.0.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) end bvf.stub(:bundler_version, v("2.a")) do - assert_equal %w[2.a], util_filter_specs(specs).map(&:version).map(&:to_s) + assert_equal %w[2 2.a 2.0 2.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) end bvf.stub(:bundler_version, v("3")) do - assert_equal %w[3 3.0], util_filter_specs(specs).map(&:version).map(&:to_s) + assert_equal %w[3 3.a 3.0 3.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) end end diff --git test/rubygems/test_gem_dependency.rb test/rubygems/test_gem_dependency.rb index d7eec3c090..3c11868671 100644 --- test/rubygems/test_gem_dependency.rb +++ test/rubygems/test_gem_dependency.rb @@ -358,7 +358,7 @@ def test_to_specs_respects_bundler_version dep.to_specs end - assert_match "Could not find 'bundler' (3.5) required by reason.\nTo update to the lastest version installed on your system, run `bundle update --bundler`.\nTo install the missing version, run `gem install bundler:3.5`\n", e.message + assert_match "Could not find 'bundler' (3.5) required by reason.\nTo update to the latest version installed on your system, run `bundle update --bundler`.\nTo install the missing version, run `gem install bundler:3.5`\n", e.message end Gem::BundlerVersionFinder.stub(:bundler_version_with_reason, ["2.0.0.pre.1", "reason"]) do