barsoom_utils 0.2.0.76 → 0.2.0.77

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc8c7ab6a54929794df46c90b1cbe14474f0461989ee071a5917176c057db757
4
- data.tar.gz: d016e08c7b0b8fe901eaabafa14027bb9da1c533967b69e078b74191c7da9693
3
+ metadata.gz: a689d68093a31c8481296dfbf97d19a683637dca75178cb142164b4ce11260a5
4
+ data.tar.gz: 8477a0ab5a7700c7bf0897c7a239ec8b48d155f934b81ffaef0c93d75c42faf9
5
5
  SHA512:
6
- metadata.gz: 0b126fb0cbb946764f8e2132e27fd8aaf546857a00caf378086ac20caeffaff5cad49a004472e89397c759e5e704d074a54fd61cf8df8277bce7b2694c511664
7
- data.tar.gz: f8d54ae7b4b409da656cc85af93cb47fc12aa436d8f59e90b39521323f9c76505cf5631713d5ac437fe1488b8c49bd2a576ed1a963d014db73234b21a6571e39
6
+ metadata.gz: bb2a240db5388ccb1634a17fd3820aa3f6dbc161ec953be78ed03ceb111e1832b0d5350adec45bd81eb1ea6133d32507243811ab106e306c1342a6d3bdfea766
7
+ data.tar.gz: 7f45fde4df510c8f92895eda05b97300dc6e3f272bb4f9220f50cb516b9748a2d1c89277f60bc1e2d24789354423bc8360d7e6992508f2831fa364943e7feb30
data/Gemfile CHANGED
@@ -15,4 +15,5 @@ group :development, :test do
15
15
  gem "redis"
16
16
  gem "rspec"
17
17
  gem "rubocop"
18
+ gem "sentry-ruby"
18
19
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0.76
1
+ 0.2.0.77
@@ -11,7 +11,9 @@ module BarsoomUtils
11
11
  raise "Expected an exception but got: #{exception.inspect}"
12
12
  end
13
13
 
14
- Honeybadger.notify(exception, context: context)
14
+ result = Honeybadger.notify(exception, context: context)
15
+ Sentry.capture_exception(exception, extra: context) if defined?(Sentry)
16
+ result
15
17
  end
16
18
 
17
19
  def self.message(message, details_or_context = nil, context_or_nothing = nil)
@@ -26,13 +28,18 @@ module BarsoomUtils
26
28
  context = {}
27
29
  end
28
30
 
29
- details ||= "(no message)"
30
-
31
- Honeybadger.notify(
31
+ result = Honeybadger.notify(
32
32
  error_class: message,
33
- error_message: details.to_s,
33
+ error_message: (details || "(no message)").to_s,
34
34
  context: context.to_h,
35
35
  )
36
+
37
+ if defined?(Sentry)
38
+ title = details ? "#{message}: #{details}" : message.to_s
39
+ Sentry.capture_message(title, extra: context.to_h)
40
+ end
41
+
42
+ result
36
43
  end
37
44
  end
38
45
  end
@@ -1,26 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
  require "barsoom_utils/exception_notifier"
3
3
  require "honeybadger"
4
+ require "sentry-ruby"
4
5
  require "fixme"
5
6
 
6
7
  RSpec.describe BarsoomUtils::ExceptionNotifier do
7
8
  before do
8
9
  allow(Honeybadger).to receive(:notify)
10
+ allow(Sentry).to receive(:capture_exception)
11
+ allow(Sentry).to receive(:capture_message)
9
12
  end
10
13
 
11
14
  describe ".notify" do
12
15
  let(:ex) { StandardError.new("boom") }
13
16
 
14
- it "passes an exception to Honeybadger" do
17
+ it "passes an exception to Honeybadger and Sentry" do
15
18
  BarsoomUtils::ExceptionNotifier.notify(ex)
16
19
 
17
20
  expect(Honeybadger).to have_received(:notify).with(ex, context: {})
21
+ expect(Sentry).to have_received(:capture_exception).with(ex, extra: {})
18
22
  end
19
23
 
20
24
  it "can pass through context info" do
21
25
  BarsoomUtils::ExceptionNotifier.notify(ex, context: { foo: "bar" })
22
26
 
23
27
  expect(Honeybadger).to have_received(:notify).with(ex, context: { foo: "bar" })
28
+ expect(Sentry).to have_received(:capture_exception).with(ex, extra: { foo: "bar" })
24
29
  end
25
30
 
26
31
  it "complains if given a non-exception" do
@@ -29,11 +34,28 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
29
34
  }.to raise_error(/Expected an exception but got:.*foo.*bar/)
30
35
 
31
36
  expect(Honeybadger).not_to have_received(:notify)
37
+ expect(Sentry).not_to have_received(:capture_exception)
38
+ end
39
+
40
+ it "returns Honeybadger's result" do
41
+ allow(Honeybadger).to receive(:notify).and_return(:sentinel)
42
+
43
+ expect(BarsoomUtils::ExceptionNotifier.notify(ex)).to eq(:sentinel)
44
+ end
45
+
46
+ context "without Sentry" do
47
+ before { hide_const("Sentry") }
48
+
49
+ it "still notifies Honeybadger and raises nothing" do
50
+ BarsoomUtils::ExceptionNotifier.notify(ex, context: { foo: "bar" })
51
+
52
+ expect(Honeybadger).to have_received(:notify).with(ex, context: { foo: "bar" })
53
+ end
32
54
  end
33
55
  end
34
56
 
35
57
  describe ".message" do
36
- it "passes a message to Honeybadger" do
58
+ it "passes a message to Honeybadger and Sentry" do
37
59
  BarsoomUtils::ExceptionNotifier.message("Boom!")
38
60
 
39
61
  expect(Honeybadger).to have_received(:notify).with(
@@ -41,6 +63,7 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
41
63
  error_message: "(no message)",
42
64
  context: {},
43
65
  )
66
+ expect(Sentry).to have_received(:capture_message).with("Boom!", extra: {})
44
67
  end
45
68
 
46
69
  it "can take a custom details string" do
@@ -51,6 +74,13 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
51
74
  error_message: "Details!",
52
75
  context: {},
53
76
  )
77
+ expect(Sentry).to have_received(:capture_message).with("Boom!: Details!", extra: {})
78
+ end
79
+
80
+ it "coerces the message to a string for Sentry" do
81
+ BarsoomUtils::ExceptionNotifier.message(:boom)
82
+
83
+ expect(Sentry).to have_received(:capture_message).with("boom", extra: {})
54
84
  end
55
85
 
56
86
  it "can take a context hash" do
@@ -61,6 +91,7 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
61
91
  error_message: "(no message)",
62
92
  context: { foo: "bar" },
63
93
  )
94
+ expect(Sentry).to have_received(:capture_message).with("Boom!", extra: { foo: "bar" })
64
95
  end
65
96
 
66
97
  it "can take a custom details string and a context hash" do
@@ -71,6 +102,27 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
71
102
  error_message: "Details!",
72
103
  context: { foo: "bar" },
73
104
  )
105
+ expect(Sentry).to have_received(:capture_message).with("Boom!: Details!", extra: { foo: "bar" })
106
+ end
107
+
108
+ it "returns Honeybadger's result" do
109
+ allow(Honeybadger).to receive(:notify).and_return(:sentinel)
110
+
111
+ expect(BarsoomUtils::ExceptionNotifier.message("Boom!")).to eq(:sentinel)
112
+ end
113
+
114
+ context "without Sentry" do
115
+ before { hide_const("Sentry") }
116
+
117
+ it "still notifies Honeybadger and raises nothing" do
118
+ BarsoomUtils::ExceptionNotifier.message("Boom!", "Details!", foo: "bar")
119
+
120
+ expect(Honeybadger).to have_received(:notify).with(
121
+ error_class: "Boom!",
122
+ error_message: "Details!",
123
+ context: { foo: "bar" },
124
+ )
125
+ end
74
126
  end
75
127
  end
76
128
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barsoom_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.76
4
+ version: 0.2.0.77
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Skogberg