mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 05:55:46 +02:00
[rubygems/rubygems] use full path for instance_eval
so that __dir__ and __FILE__ will work properly from within that gemfile
fragment, if eval_gemfile is given a relative path
d521bf9790
This commit is contained in:
parent
8f17b3bd27
commit
fa334ecd40
2 changed files with 12 additions and 1 deletions
|
@ -46,7 +46,7 @@ module Bundler
|
||||||
@gemfile = expanded_gemfile_path
|
@gemfile = expanded_gemfile_path
|
||||||
@gemfiles << expanded_gemfile_path
|
@gemfiles << expanded_gemfile_path
|
||||||
contents ||= Bundler.read_file(@gemfile.to_s)
|
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
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
||||||
message = "There was an error " \
|
message = "There was an error " \
|
||||||
"#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \
|
"#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \
|
||||||
|
|
|
@ -134,6 +134,17 @@ RSpec.describe Bundler::Dsl do
|
||||||
expect { subject.eval_gemfile("Gemfile") }.
|
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/)
|
to raise_error(Bundler::GemfileError, /There was an error evaluating `Gemfile`: ruby_version must match the :engine_version for MRI/)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "#gem" do
|
describe "#gem" do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue