summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNgan Pham <ngan@users.noreply.github.com>2023-08-17 21:19:58 -0700
committergit <svn-admin@ruby-lang.org>2023-08-18 19:14:14 +0000
commit3d7a0301124aa1fb4a6fc1a92baf4f2601b8d2ea (patch)
tree9e041da9d9031f4012211f7df24e7d7001a31c69
parente1505aebf2dd5876db227f3e0c70e9ad1c4302fd (diff)
[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
-rw-r--r--lib/bundler/ruby_dsl.rb2
-rw-r--r--spec/bundler/bundler/ruby_dsl_spec.rb7
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"