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
7 changes: 1 addition & 6 deletions lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,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
Expand Down
13 changes: 1 addition & 12 deletions lib/rubygems/bundler_version_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
require "rubygems/util"

module Gem::BundlerVersionFinder
@without_filtering = false

def self.without_filtering
without_filtering, @without_filtering = true, @without_filtering
Copy link
Copy Markdown
Contributor Author

@deivid-rodriguez deivid-rodriguez Oct 6, 2018

Choose a reason for hiding this comment

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

So, I have no idea what this filtering intends to do, but I think the problem is that here the assignment is inverted (it should be without_filtering, @without_filtering = @without_filtering, true). That means that once the instance variable is set to true, it's never switched back. Since this variable is used further below in the bundler_version_with_reason method to prevent the method from returning an useful message, that's what it ends up happening.

So, I think this could also be fixed by inverting the assignment but I wonder what we're trying to achieve with all this untested code... 🤷‍♂️.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤦 yeah I think that sounds right

yield
ensure
@without_filtering = without_filtering
end

def self.bundler_version
version, _ = bundler_version_with_reason

Expand All @@ -21,8 +12,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
Expand All @@ -40,7 +29,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
Expand Down
35 changes: 35 additions & 0 deletions test/rubygems/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,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'
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down