-
-
Notifications
You must be signed in to change notification settings - Fork 481
/
integrable_spec.rb
104 lines (78 loc) · 2.95 KB
/
integrable_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require "spec_helper"
require "sentry/integrable"
RSpec.describe Sentry::Integrable do
module Sentry
module FakeIntegration
extend Sentry::Integrable
register_integration name: "fake_integration", version: "0.1.0"
end
end
it "registers correct meta" do
meta = Sentry.integrations["fake_integration"]
expect(meta).to eq({ name: "sentry.ruby.fake_integration", version: "0.1.0" })
end
context "when the SDK is initialized" do
let(:io) { StringIO.new }
let(:logger) { Logger.new(io) }
module Sentry
module AnotherIntegration; end
end
before do
perform_basic_setup do |config|
config.logger = logger
end
end
it "logs warning message about the incorrect loading order" do
Sentry::AnotherIntegration.extend Sentry::Integrable
Sentry::AnotherIntegration.register_integration name: "another_integration", version: "0.1.0"
expect(io.string).to match(/Integration 'another_integration' is loaded after the SDK is initialized/)
end
end
describe "helpers generation" do
before do
perform_basic_setup
end
let(:exception) { ZeroDivisionError.new("1/0") }
let(:message) { "test message" }
it "generates Sentry::FakeIntegration.capture_exception" do
hint = nil
event = nil
Sentry.configuration.before_send = lambda do |e, h|
hint = h
event = e
event
end
Sentry::FakeIntegration.capture_exception(exception, hint: { additional_hint: "foo" })
expect(hint).to eq({ additional_hint: "foo", integration: "fake_integration", exception: exception })
mechanism = event.exception.values.first.mechanism
expect(mechanism.type).to eq('fake_integration')
expect(mechanism.handled).to eq(false)
end
it "generates Sentry::FakeIntegration.capture_message" do
hint = nil
Sentry.configuration.before_send = lambda do |event, h|
hint = h
event
end
Sentry::FakeIntegration.capture_message(message, hint: { additional_hint: "foo" })
expect(hint).to eq({ additional_hint: "foo", integration: "fake_integration", message: message })
end
it "generates Sentry::FakeIntegration.capture_check_in" do
hint = nil
Sentry.configuration.before_send = lambda do |event, h|
hint = h
event
end
Sentry::FakeIntegration.capture_check_in("test_slug", :ok, hint: { additional_hint: "foo" })
expect(hint).to eq({ additional_hint: "foo", integration: "fake_integration", slug: "test_slug" })
end
it "sets correct meta when the event is captured by integration helpers" do
event = Sentry::FakeIntegration.capture_message(message)
expect(event.sdk).to eq({ name: "sentry.ruby.fake_integration", version: "0.1.0" })
end
it "doesn't change the events captured by original helpers" do
event = Sentry.capture_message(message)
expect(event.sdk).to eq(Sentry.sdk_meta)
end
end
end