Skip to content

Commit

Permalink
Use __LINE__ math instead of executing heredoc with eval
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Jun 26, 2024
1 parent f287412 commit ea73805
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions language/heredoc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@

it "reports line numbers inside HEREDOC with method call" do
-> {
eval %{<<HERE.chomp\na\nb\#{c}\nHERE}, nil, "example"
}.should raise_error(NameError) { |e| e.backtrace[0].should.start_with?("example:3") }
<<-HERE.chomp
a
b
#{c}
HERE
}.should raise_error(NameError) { |e| e.backtrace[0].should.start_with?("#{__FILE__}:#{__LINE__ - 2}") }
end
end

0 comments on commit ea73805

Please sign in to comment.