2021-01-08 22:32:15 +00:00
|
|
|
require "./spec_helper"
|
|
|
|
|
|
|
|
Spectator.describe Spectator do
|
|
|
|
let(current_example) { ::Spectator::Harness.current.example }
|
|
|
|
subject(source) { current_example.source }
|
|
|
|
|
|
|
|
context "line numbers" do
|
2021-03-30 04:18:08 +00:00
|
|
|
it "contains starting line of spec" do
|
|
|
|
expect(source.line).to eq(__LINE__ - 1)
|
|
|
|
end
|
2021-01-08 22:32:15 +00:00
|
|
|
|
2021-03-30 04:18:08 +00:00
|
|
|
it "contains ending line of spec" do
|
|
|
|
expect(source.end_line).to eq(__LINE__ + 1)
|
2021-01-08 22:32:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "handles multiple lines and examples" do
|
|
|
|
# Offset is important.
|
2021-03-30 04:18:08 +00:00
|
|
|
expect(source.line).to eq(__LINE__ - 2)
|
2021-03-30 19:31:23 +00:00
|
|
|
# This line fails, refer to https://github.com/crystal-lang/crystal/issues/10562
|
|
|
|
# expect(source.end_line).to eq(__LINE__ + 2)
|
2021-03-30 04:18:08 +00:00
|
|
|
# Offset is still important.
|
2021-01-08 22:32:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "file names" do
|
|
|
|
subject { source.file }
|
|
|
|
|
|
|
|
it "match source code" do
|
|
|
|
is_expected.to eq(__FILE__)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|