Fix line numbers being wrong with macro expansion

Addresses https://github.com/icy-arctic-fox/spectator/issues/18
This commit is contained in:
Michael Miller 2021-01-08 15:32:15 -07:00
parent 891cd4bbf7
commit 2ecd4ded6d
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
4 changed files with 39 additions and 12 deletions

27
spec/line_number_spec.cr Normal file
View file

@ -0,0 +1,27 @@
require "./spec_helper"
Spectator.describe Spectator do
let(current_example) { ::Spectator::Harness.current.example }
subject(source) { current_example.source }
context "line numbers" do
subject { source.line }
it "match source code" do
is_expected.to eq(__LINE__ - 1)
end
it "handles multiple lines and examples" do
# Offset is important.
is_expected.to eq(__LINE__ - 2)
end
end
context "file names" do
subject { source.file }
it "match source code" do
is_expected.to eq(__FILE__)
end
end
end