mirror of
https://gitea.invidious.io/iv-org/shard-backtracer.cr.git
synced 2024-08-15 00:53:13 +00:00
Add specs for Frame#context
This commit is contained in:
parent
d88a17f3e6
commit
0663fbfa01
1 changed files with 35 additions and 0 deletions
|
@ -23,4 +23,39 @@ describe Backtracer::Backtrace::Frame do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue