Skip to content

Commit

Permalink
Merge pull request #7471 from ccutrer/eval_gemfile_absolute_path
Browse files Browse the repository at this point in the history
Use full path for `instance_eval` in `Bundler::DSL#eval_gemfile`
  • Loading branch information
simi committed Feb 15, 2024
2 parents 81a05bf + d521bf9 commit 484e1aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bundler/lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def eval_gemfile(gemfile, contents = nil)
@gemfile = expanded_gemfile_path
@gemfiles << expanded_gemfile_path
contents ||= Bundler.read_file(@gemfile.to_s)
instance_eval(contents, gemfile.to_s, 1)
instance_eval(contents, @gemfile.to_s, 1)
rescue Exception => e # rubocop:disable Lint/RescueException
message = "There was an error " \
"#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \
Expand Down
11 changes: 11 additions & 0 deletions bundler/spec/bundler/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@
expect { subject.eval_gemfile("Gemfile") }.
to raise_error(Bundler::GemfileError, /There was an error evaluating `Gemfile`: ruby_version must match the :engine_version for MRI/)
end

it "populates __dir__ and __FILE__ correctly" do
abs_path = source_root.join("../fragment.rb").to_s
expect(Bundler).to receive(:read_file).with(abs_path).and_return(<<~RUBY)
@fragment_dir = __dir__
@fragment_file = __FILE__
RUBY
subject.eval_gemfile("../fragment.rb")
expect(subject.instance_variable_get(:@fragment_dir)).to eq(source_root.dirname.to_s)
expect(subject.instance_variable_get(:@fragment_file)).to eq(abs_path)
end
end

describe "#gem" do
Expand Down

0 comments on commit 484e1aa

Please sign in to comment.