barsoom_utils 0.2.0.77 → 0.3.0.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/VERSION +1 -1
- data/lib/barsoom_utils/exception_notifier.rb +14 -13
- data/spec/exception_notifier_spec.rb +17 -50
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d567d7a3ae76f80b86ad642cf590526cb3bc2a2be5b95c94abf8944142a40b15
|
|
4
|
+
data.tar.gz: 0fd5468990225ed9d0faf43d860b6afe2ccb5b24fb5786077cde7054445ea832
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ce1a9a7ef20a8f445b8974a3e63b471c1b20ca952f2608e2fb6e35a9f502a8ef961f4d9087dd02cc6e41a6ba9e234df7ba812f6cac42d057d49a3cc00ba02abd
|
|
7
|
+
data.tar.gz: 787e53e219778ea27306a49758ce0220fbfa1be5e57743f0b5a14a14fe56288d07f914ae885cacf996e2c02dc9ed35151907457b0a0f1f7e4b2fc2bc818c2483
|
data/Gemfile
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.3.0.79
|
|
@@ -11,12 +11,14 @@ module BarsoomUtils
|
|
|
11
11
|
raise "Expected an exception but got: #{exception.inspect}"
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
ensure_notifier!
|
|
15
|
+
|
|
16
|
+
Sentry.capture_exception(exception, extra: context)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def self.message(message, details_or_context = nil, context_or_nothing = nil)
|
|
20
|
+
ensure_notifier!
|
|
21
|
+
|
|
20
22
|
if context_or_nothing
|
|
21
23
|
details = details_or_context
|
|
22
24
|
context = context_or_nothing
|
|
@@ -28,18 +30,17 @@ module BarsoomUtils
|
|
|
28
30
|
context = {}
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
context: context.to_h,
|
|
35
|
-
)
|
|
33
|
+
title = details ? "#{message}: #{details}" : message.to_s
|
|
34
|
+
Sentry.capture_message(title, extra: context.to_h)
|
|
35
|
+
end
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
private_class_method \
|
|
40
|
+
def self.ensure_notifier!
|
|
41
|
+
return if defined?(Sentry)
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
raise "Cannot notify: Sentry is not available."
|
|
43
44
|
end
|
|
44
45
|
end
|
|
45
46
|
end
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
require "barsoom_utils/exception_notifier"
|
|
3
|
-
require "honeybadger"
|
|
4
3
|
require "sentry-ruby"
|
|
5
4
|
require "fixme"
|
|
6
5
|
|
|
7
6
|
RSpec.describe BarsoomUtils::ExceptionNotifier do
|
|
8
7
|
before do
|
|
9
|
-
allow(Honeybadger).to receive(:notify)
|
|
10
8
|
allow(Sentry).to receive(:capture_exception)
|
|
11
9
|
allow(Sentry).to receive(:capture_message)
|
|
12
10
|
end
|
|
@@ -14,17 +12,15 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
|
|
|
14
12
|
describe ".notify" do
|
|
15
13
|
let(:ex) { StandardError.new("boom") }
|
|
16
14
|
|
|
17
|
-
it "passes an exception to
|
|
15
|
+
it "passes an exception to Sentry" do
|
|
18
16
|
BarsoomUtils::ExceptionNotifier.notify(ex)
|
|
19
17
|
|
|
20
|
-
expect(Honeybadger).to have_received(:notify).with(ex, context: {})
|
|
21
18
|
expect(Sentry).to have_received(:capture_exception).with(ex, extra: {})
|
|
22
19
|
end
|
|
23
20
|
|
|
24
21
|
it "can pass through context info" do
|
|
25
22
|
BarsoomUtils::ExceptionNotifier.notify(ex, context: { foo: "bar" })
|
|
26
23
|
|
|
27
|
-
expect(Honeybadger).to have_received(:notify).with(ex, context: { foo: "bar" })
|
|
28
24
|
expect(Sentry).to have_received(:capture_exception).with(ex, extra: { foo: "bar" })
|
|
29
25
|
end
|
|
30
26
|
|
|
@@ -33,51 +29,38 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
|
|
|
33
29
|
BarsoomUtils::ExceptionNotifier.notify({ foo: "bar" })
|
|
34
30
|
}.to raise_error(/Expected an exception but got:.*foo.*bar/)
|
|
35
31
|
|
|
36
|
-
expect(Honeybadger).not_to have_received(:notify)
|
|
37
32
|
expect(Sentry).not_to have_received(:capture_exception)
|
|
38
33
|
end
|
|
39
34
|
|
|
40
|
-
it "returns
|
|
41
|
-
allow(
|
|
35
|
+
it "returns Sentry's result" do
|
|
36
|
+
allow(Sentry).to receive(:capture_exception).and_return(:sentinel)
|
|
42
37
|
|
|
43
38
|
expect(BarsoomUtils::ExceptionNotifier.notify(ex)).to eq(:sentinel)
|
|
44
39
|
end
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
it "raises without Sentry" do
|
|
42
|
+
hide_const("Sentry")
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
BarsoomUtils::ExceptionNotifier.notify(ex
|
|
51
|
-
|
|
52
|
-
expect(Honeybadger).to have_received(:notify).with(ex, context: { foo: "bar" })
|
|
53
|
-
end
|
|
44
|
+
expect {
|
|
45
|
+
BarsoomUtils::ExceptionNotifier.notify(ex)
|
|
46
|
+
}.to raise_error(/Sentry is not available/)
|
|
54
47
|
end
|
|
55
48
|
end
|
|
56
49
|
|
|
57
50
|
describe ".message" do
|
|
58
|
-
it "passes a message to
|
|
51
|
+
it "passes a message to Sentry" do
|
|
59
52
|
BarsoomUtils::ExceptionNotifier.message("Boom!")
|
|
60
53
|
|
|
61
|
-
expect(Honeybadger).to have_received(:notify).with(
|
|
62
|
-
error_class: "Boom!",
|
|
63
|
-
error_message: "(no message)",
|
|
64
|
-
context: {},
|
|
65
|
-
)
|
|
66
54
|
expect(Sentry).to have_received(:capture_message).with("Boom!", extra: {})
|
|
67
55
|
end
|
|
68
56
|
|
|
69
57
|
it "can take a custom details string" do
|
|
70
58
|
BarsoomUtils::ExceptionNotifier.message("Boom!", "Details!")
|
|
71
59
|
|
|
72
|
-
expect(Honeybadger).to have_received(:notify).with(
|
|
73
|
-
error_class: "Boom!",
|
|
74
|
-
error_message: "Details!",
|
|
75
|
-
context: {},
|
|
76
|
-
)
|
|
77
60
|
expect(Sentry).to have_received(:capture_message).with("Boom!: Details!", extra: {})
|
|
78
61
|
end
|
|
79
62
|
|
|
80
|
-
it "coerces the message to a string
|
|
63
|
+
it "coerces the message to a string" do
|
|
81
64
|
BarsoomUtils::ExceptionNotifier.message(:boom)
|
|
82
65
|
|
|
83
66
|
expect(Sentry).to have_received(:capture_message).with("boom", extra: {})
|
|
@@ -86,43 +69,27 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
|
|
|
86
69
|
it "can take a context hash" do
|
|
87
70
|
BarsoomUtils::ExceptionNotifier.message("Boom!", foo: "bar")
|
|
88
71
|
|
|
89
|
-
expect(Honeybadger).to have_received(:notify).with(
|
|
90
|
-
error_class: "Boom!",
|
|
91
|
-
error_message: "(no message)",
|
|
92
|
-
context: { foo: "bar" },
|
|
93
|
-
)
|
|
94
72
|
expect(Sentry).to have_received(:capture_message).with("Boom!", extra: { foo: "bar" })
|
|
95
73
|
end
|
|
96
74
|
|
|
97
75
|
it "can take a custom details string and a context hash" do
|
|
98
76
|
BarsoomUtils::ExceptionNotifier.message("Boom!", "Details!", foo: "bar")
|
|
99
77
|
|
|
100
|
-
expect(Honeybadger).to have_received(:notify).with(
|
|
101
|
-
error_class: "Boom!",
|
|
102
|
-
error_message: "Details!",
|
|
103
|
-
context: { foo: "bar" },
|
|
104
|
-
)
|
|
105
78
|
expect(Sentry).to have_received(:capture_message).with("Boom!: Details!", extra: { foo: "bar" })
|
|
106
79
|
end
|
|
107
80
|
|
|
108
|
-
it "returns
|
|
109
|
-
allow(
|
|
81
|
+
it "returns Sentry's result" do
|
|
82
|
+
allow(Sentry).to receive(:capture_message).and_return(:sentinel)
|
|
110
83
|
|
|
111
84
|
expect(BarsoomUtils::ExceptionNotifier.message("Boom!")).to eq(:sentinel)
|
|
112
85
|
end
|
|
113
86
|
|
|
114
|
-
|
|
115
|
-
|
|
87
|
+
it "raises without Sentry" do
|
|
88
|
+
hide_const("Sentry")
|
|
116
89
|
|
|
117
|
-
|
|
118
|
-
BarsoomUtils::ExceptionNotifier.message("Boom!"
|
|
119
|
-
|
|
120
|
-
expect(Honeybadger).to have_received(:notify).with(
|
|
121
|
-
error_class: "Boom!",
|
|
122
|
-
error_message: "Details!",
|
|
123
|
-
context: { foo: "bar" },
|
|
124
|
-
)
|
|
125
|
-
end
|
|
90
|
+
expect {
|
|
91
|
+
BarsoomUtils::ExceptionNotifier.message("Boom!")
|
|
92
|
+
}.to raise_error(/Sentry is not available/)
|
|
126
93
|
end
|
|
127
94
|
end
|
|
128
95
|
end
|