Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/rubygems/bundler_version_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def self.filter!(specs)
return unless bundler_version = self.bundler_version

specs.reject! { |spec| spec.version.segments.first != bundler_version.segments.first }

exact_match_index = specs.find_index { |spec| spec.version == bundler_version }
return unless exact_match_index

specs.unshift(specs.delete_at(exact_match_index))
end

def self.bundle_update_bundler_version
Expand Down
34 changes: 34 additions & 0 deletions test/rubygems/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,40 @@ def test_activate_bin_path_gives_proper_error_for_bundler
refute_includes e.message, "can't find gem bundler (>= 0.a) with executable bundle"
end

def test_activate_bin_path_selects_exact_bundler_version_if_present
bundler_latest = util_spec 'bundler', '2.0.1' do |s|
s.executables = ['bundle']
end

bundler_previous = util_spec 'bundler', '2.0.0' do |s|
s.executables = ['bundle']
end

install_specs bundler_latest, bundler_previous

File.open("Gemfile.lock", "w") do |f|
f.write <<-L.gsub(/ {8}/, "")
GEM
remote: https://rubygems.org/
specs:

PLATFORMS
ruby

DEPENDENCIES

BUNDLED WITH
2.0.0
L
end

File.open("Gemfile", "w") { |f| f.puts('source "https://rubygems.org"') }

load Gem.activate_bin_path("bundler", "bundle", ">= 0.a")

assert_equal %w(bundler-2.0.0), loaded_spec_names
end

def test_self_bin_path_no_exec_name
e = assert_raises ArgumentError do
Gem.bin_path 'a'
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_bundler_version_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ 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 2.a 2.0 2.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
assert_equal %w[2.a 2 2.0 2.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change this existing expectation. The new expectation makes more sense to me. If we have a prerelease in the BUNDLED WITH section, we still want that activated even if it is a prerelease... right? 🤔

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm good question! I'm not sure how we want to handle autoswitching if the locked version is a prerelease. probably using the exact version is the safest, so I think this is a good place to start.

end
bvf.stub(:bundler_version, v("3")) do
assert_equal %w[3 3.a 3.0 3.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
Expand Down