[rubygems/rubygems] Resolve ruby version file relative to bundle root

This is a follow up to https://github.com/rubygems/rubygems/issues/6742.
This change makes it so that the version file is resolved relative to
the Bundle root instead of the working directory.

Why is this useful?

If you run a commnad (eg `rails`) from the `app/` directory, your bundle
would fail to load.

https://github.com/rubygems/rubygems/commit/6d47ee98b9
This commit is contained in:
Ngan Pham 2023-08-17 21:19:58 -07:00 committed by git
parent e1505aebf2
commit 3d7a030112
2 changed files with 7 additions and 2 deletions

View File

@ -11,7 +11,7 @@ module Bundler
if options[:file]
raise GemfileError, "Cannot specify version when using the file option" if ruby_version.any?
ruby_version << Bundler.read_file(options[:file]).strip
ruby_version << Bundler.read_file(Bundler.root.join(options[:file])).strip
end
if options[:engine] == "ruby" && options[:engine_version] &&

View File

@ -104,7 +104,12 @@ RSpec.describe Bundler::RubyDsl do
let(:engine_version) { version }
let(:patchlevel) { nil }
let(:engine) { "ruby" }
before { allow(Bundler).to receive(:read_file).with("foo").and_return("#{version}\n") }
let(:project_root) { Pathname.new("/path/to/project") }
before do
allow(Bundler).to receive(:read_file).with(project_root.join("foo")).and_return("#{version}\n")
allow(Bundler).to receive(:root).and_return(Pathname.new("/path/to/project"))
end
it_behaves_like "it stores the ruby version"