Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix __FILE__ and __dir__ in primary Gemfiles #193

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/appraisal/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ module Appraisal
# Load bundler Gemfiles and merge dependencies
class Gemfile < BundlerDSL
def load(path)
if File.exist?(path)
run(IO.read(path))
end
run(IO.read(path), path) if File.exist?(path)
end

def run(definitions)
instance_eval(definitions, __FILE__, __LINE__) if definitions
def run(definitions, path, line = 1)
instance_eval(definitions, path, line) if definitions
end

def dup
Gemfile.new.tap do |gemfile|
gemfile.git_sources = @git_sources
gemfile.run(for_dup)
gemfile.run(for_dup, __FILE__, __LINE__)
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/appraisal/gemfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,13 @@
expect(gemfile.to_s).to eq %(gem "bacon", git: "../path/bacon_pancake")
end
end

it "preserves the Gemfile's __FILE__" do
gemfile = Appraisal::Gemfile.new
Tempfile.open do |tmpfile|
tmpfile.write "__FILE__"
tmpfile.rewind
expect(gemfile.load(tmpfile.path)).to include(File.dirname(tmpfile.path))
end
end
end