shard-backtracer.cr/spec/spec_helper.cr

38 lines
851 B
Crystal
Raw Permalink Normal View History

2020-12-27 16:12:47 +00:00
require "spec"
require "../src/backtracer"
2021-01-01 15:12:57 +00:00
def with_configuration(shared = true, &)
2021-01-01 15:12:57 +00:00
yield shared ? Backtracer.configuration : Backtracer::Configuration.new
end
def with_backtrace(backtrace, **options, &)
2021-01-01 15:12:57 +00:00
yield Backtracer::Backtrace::Parser.parse(backtrace, **options)
end
def with_frame(method, path = nil, lineno = nil, column = nil, **options, &)
2021-01-01 15:12:57 +00:00
line = String.build do |io|
if path
io << path
io << ':' << lineno if lineno
io << ':' << column if column
io << " in '" << method << '\''
else
io << method
end
end
yield Backtracer::Backtrace::Frame::Parser.parse(line, **options)
end
def with_foo_frame(
method = "foo_bar?",
path = "#{__DIR__}/foo.cr",
lineno = 1,
column = 7,
**options,
&
2021-01-01 15:12:57 +00:00
)
with_frame(method, path, lineno, column, **options) do |frame|
yield frame
end
end