Skip to content

Commit 925bf25

Browse files
committed
Improve Backtrace's specs
1 parent 92c01b9 commit 925bf25

1 file changed

Lines changed: 41 additions & 7 deletions

File tree

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
11
require 'spec_helper'
22

33
RSpec.describe Sentry::Backtrace do
4-
let(:configuration) { Sentry::Configuration.new }
4+
let(:fixture_root) { File.join(Dir.pwd, "spec", "support") }
5+
let(:fixture_file) { File.join(fixture_root, "stacktrace_test_fixture.rb") }
6+
let(:configuration) do
7+
Sentry::Configuration.new.tap do |config|
8+
config.project_root = fixture_root
9+
end
10+
end
11+
512
let(:backtrace) do
6-
Sentry::Backtrace.parse(Thread.current.backtrace, configuration.project_root, configuration.app_dirs_pattern)
13+
[
14+
"#{fixture_file}:6:in `bar'",
15+
"#{fixture_file}:2:in `foo'"
16+
]
17+
end
18+
19+
let(:parsed_backtrace) do
20+
described_class.parse(backtrace, fixture_root, configuration.app_dirs_pattern)
21+
end
22+
23+
describe ".parse" do
24+
it "returns an array of StacktraceInterface::Frames with correct information" do
25+
lines = parsed_backtrace.lines.reverse
26+
27+
expect(lines.count).to eq(2)
28+
29+
first_line = lines.first
30+
31+
expect(first_line.file).to match(/stacktrace_test_fixture.rb/)
32+
expect(first_line.method).to eq("foo")
33+
expect(first_line.number).to eq(2)
34+
35+
second_line = lines.last
36+
37+
expect(second_line.file).to match(/stacktrace_test_fixture.rb/)
38+
expect(second_line.method).to eq("bar")
39+
expect(second_line.number).to eq(6)
40+
end
741
end
842

943
it "calls backtrace_cleanup_callback if it's present in the configuration" do
@@ -18,19 +52,19 @@
1852
end
1953

2054
it "#lines" do
21-
expect(backtrace.lines.first).to be_a(Sentry::Backtrace::Line)
55+
expect(parsed_backtrace.lines.first).to be_a(Sentry::Backtrace::Line)
2256
end
2357

2458
it "#inspect" do
25-
expect(backtrace.inspect).to match(/Backtrace: .*>$/)
59+
expect(parsed_backtrace.inspect).to match(/Backtrace: .*>$/)
2660
end
2761

2862
it "#to_s" do
29-
expect(backtrace.to_s).to match(/backtrace_spec.rb:\d/)
63+
expect(parsed_backtrace.to_s).to match(/stacktrace_test_fixture.rb:\d/)
3064
end
3165

3266
it "==" do
33-
backtrace2 = Sentry::Backtrace.new(backtrace.lines)
34-
expect(backtrace).to be == backtrace2
67+
backtrace2 = Sentry::Backtrace.new(parsed_backtrace.lines)
68+
expect(parsed_backtrace).to be == backtrace2
3569
end
3670
end

0 commit comments

Comments
 (0)