Add specs for Frame#context

This commit is contained in:
Sijawusz Pur Rahnama 2021-01-03 17:56:44 +01:00
parent d88a17f3e6
commit 0663fbfa01

View file

@ -23,4 +23,39 @@ describe Backtracer::Backtrace::Frame do
end
end
end
{% unless flag?(:release) || !flag?(:debug) %}
describe "#context" do
it "returns proper lines" do
with_configuration do |configuration|
with_backtrace(caller) do |backtrace|
backtrace.frames.first.tap do |first_frame|
context_lines = configuration.context_lines.should_not be_nil
context = first_frame.context.should_not be_nil
lines = File.read_lines(__FILE__)
lineidx = context.lineno - 1
context.pre
.should eq(lines[Math.max(0, lineidx - context_lines), context_lines]?)
context.line
.should eq(lines[lineidx]?)
context.post
.should eq(lines[Math.min(lines.size, lineidx + 1), context_lines]?)
end
end
end
end
it "returns given amount of lines" do
with_backtrace(caller) do |backtrace|
backtrace.frames.first.tap do |first_frame|
context = first_frame.context(3).should_not be_nil
context.pre.size.should eq(3)
context.post.size.should eq(3)
end
end
end
end
{% end %}
end