From 3d7a0301124aa1fb4a6fc1a92baf4f2601b8d2ea Mon Sep 17 00:00:00 2001 From: Ngan Pham Date: Thu, 17 Aug 2023 21:19:58 -0700 Subject: [PATCH] [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 --- lib/bundler/ruby_dsl.rb | 2 +- spec/bundler/bundler/ruby_dsl_spec.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/bundler/ruby_dsl.rb b/lib/bundler/ruby_dsl.rb index d054969e8d..7c101c794f 100644 --- a/lib/bundler/ruby_dsl.rb +++ b/lib/bundler/ruby_dsl.rb @@ -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] && diff --git a/spec/bundler/bundler/ruby_dsl_spec.rb b/spec/bundler/bundler/ruby_dsl_spec.rb index 0ba55e949f..70424312ce 100644 --- a/spec/bundler/bundler/ruby_dsl_spec.rb +++ b/spec/bundler/bundler/ruby_dsl_spec.rb @@ -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"