|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | 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 | + |
5 | 12 | 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 |
7 | 41 | end |
8 | 42 |
|
9 | 43 | it "calls backtrace_cleanup_callback if it's present in the configuration" do |
|
18 | 52 | end |
19 | 53 |
|
20 | 54 | 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) |
22 | 56 | end |
23 | 57 |
|
24 | 58 | it "#inspect" do |
25 | | - expect(backtrace.inspect).to match(/Backtrace: .*>$/) |
| 59 | + expect(parsed_backtrace.inspect).to match(/Backtrace: .*>$/) |
26 | 60 | end |
27 | 61 |
|
28 | 62 | 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/) |
30 | 64 | end |
31 | 65 |
|
32 | 66 | 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 |
35 | 69 | end |
36 | 70 | end |
0 commit comments