exceptions 0.0.6 → 0.0.7

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
  SHA1:
3
- metadata.gz: e22bde9b588254869a161c750b9e5f9407857d69
4
- data.tar.gz: 39ce679d0cc456ca8cdc676e8885abf806f95b7a
3
+ metadata.gz: f919423137f3aa99b716901546a5cb9fb0e50d8c
4
+ data.tar.gz: 2d5176e0c638e4b92cd7fb1fc6966edfa840df82
5
5
  SHA512:
6
- metadata.gz: 8a66bc3bd68635ed142354ced7e2289790ea357b047fa90f37df7672008f4920e41d85be492b017108c8ff848188d70c9713c140d479210b8fb4a0c3f01180a6
7
- data.tar.gz: b8e437c1c02bff288ef0c5c1991a4a11ef15612e106fe42911952b65108b8de1a3c93a61a07442941b82548fa94eddfa942ca37dc8b721c66507839818ec294f
6
+ metadata.gz: 6e7eaa404821953f1c3d59b3c6fdea2a4273e824a726ef1e5fd2d27e101ad686348aa464c0002ca26405a1e47f8e657624712e45a66faa750a8461597eadf90e
7
+ data.tar.gz: 2921f752da6ae19f505519c8115e0d35b170e5fc639159864f6150d64d4b431a14e40175f97a370829f7102c92571a2c94c24e32d34172251c0272427e4df9b9
@@ -5,8 +5,14 @@ module Exceptions
5
5
  # Public: The Honeybadger backend is a Backend implementation that sends the
6
6
  # exception to Honeybadger.
7
7
  class Honeybadger < Backend
8
+ attr_reader :honeybadger
9
+
10
+ def initialize(honeybadger = ::Honeybadger)
11
+ @honeybadger = honeybadger
12
+ end
13
+
8
14
  def notify(exception, options = {})
9
- if id = ::Honeybadger.notify_or_ignore(exception, options)
15
+ if id = honeybadger.notify_or_ignore(exception, options)
10
16
  Result.new id
11
17
  else
12
18
  BadResult.new
@@ -14,15 +20,15 @@ module Exceptions
14
20
  end
15
21
 
16
22
  def context(ctx)
17
- ::Honeybadger.context ctx
23
+ honeybadger.context ctx
18
24
  end
19
25
 
20
26
  def clear_context
21
- ::Honeybadger.clear!
27
+ honeybadger.clear!
22
28
  end
23
29
 
24
30
  def rack_exception(exception, env)
25
- notify(exception, rack_env: env) unless ::Honeybadger.
31
+ notify(exception, rack_env: env) unless honeybadger.
26
32
  configuration.
27
33
  ignore_user_agent.
28
34
  flatten.
@@ -11,6 +11,7 @@ module Exceptions
11
11
 
12
12
  def notify(exception, options = {})
13
13
  logger.info exception
14
+ Result.new
14
15
  end
15
16
  end
16
17
  end
@@ -10,9 +10,18 @@ module Exceptions
10
10
  end
11
11
 
12
12
  def notify(exception, options = {})
13
- backends.each do |backend|
13
+ results = backends.map do |backend|
14
14
  backend.notify exception, options
15
15
  end
16
+
17
+ MultiResult.new results.map(&:id), results.map(&:url)
18
+ end
19
+
20
+ class MultiResult < ::Exceptions::Result
21
+ def initialize(ids, urls)
22
+ @id = ids.join(',')
23
+ @url = urls.join(',')
24
+ end
16
25
  end
17
26
  end
18
27
  end
@@ -2,7 +2,9 @@ module Exceptions
2
2
  module Backends
3
3
  # Public: Null is an implementation of the Backend interface that does nothing.
4
4
  class Null < Backend
5
- def notify(exception, options = {}); end
5
+ def notify(exception, options = {})
6
+ Result.new
7
+ end
6
8
  end
7
9
  end
8
10
  end
@@ -9,14 +9,14 @@ module Exceptions
9
9
  # This class is mostly a reference implementation but anything that conforms to the
10
10
  # above interface is acceptable to return.
11
11
  class Result
12
- attr_reader :id
12
+ attr_reader :id, :url
13
13
 
14
14
  def initialize(id = nil)
15
15
  @id = id
16
16
  end
17
17
 
18
18
  def url
19
- ""
19
+ @url ||= ""
20
20
  end
21
21
 
22
22
  def ok?
@@ -1,3 +1,3 @@
1
1
  module Exceptions
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Exceptions::Backends::Honeybadger do
4
+ let(:honeybadger) { double(::Honeybadger) }
5
+
6
+ let(:backend) do
7
+ described_class.new honeybadger
8
+ end
9
+
10
+ describe '#notify' do
11
+ subject(:result) { backend.notify(boom) }
12
+
13
+ context 'when successful' do
14
+ before do
15
+ expect(honeybadger).to receive(:notify_or_ignore).and_return('1234')
16
+ end
17
+
18
+ it 'returns the result' do
19
+ expect(result.id).to eq '1234'
20
+ end
21
+ end
22
+
23
+ context 'when errored' do
24
+ before do
25
+ expect(honeybadger).to receive(:notify_or_ignore).and_return(nil)
26
+ end
27
+
28
+ it 'returns the result' do
29
+ expect(result.id).to eq nil
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Exceptions::Backends::Multi do
4
+ let(:backend) do
5
+ described_class.new \
6
+ double(Exceptions::Backend, notify: double(Exceptions::Result, id: 1, url: 'http://www.foo.bar')),
7
+ double(Exceptions::Backend, notify: double(Exceptions::Result, id: 2, url: 'http://www.bar.foo'))
8
+ end
9
+
10
+ describe '#notify' do
11
+ describe 'result' do
12
+ subject(:result) { backend.notify(boom) }
13
+
14
+ specify { expect(result.id).to eq '1,2' }
15
+ specify { expect(result.url).to eq 'http://www.foo.bar,http://www.bar.foo' }
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exceptions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
@@ -94,7 +94,9 @@ files:
94
94
  - lib/exceptions/version.rb
95
95
  - lib/rack/exceptions.rb
96
96
  - spec/exceptions/backends/honeybadger/integration_spec.rb
97
+ - spec/exceptions/backends/honeybadger_spec.rb
97
98
  - spec/exceptions/backends/logger/integration_spec.rb
99
+ - spec/exceptions/backends/multi_spec.rb
98
100
  - spec/rack/exceptions_spec.rb
99
101
  - spec/spec_helper.rb
100
102
  - spec/support/honeybadger.rb
@@ -124,7 +126,9 @@ specification_version: 4
124
126
  summary: Exceptions is a Ruby gem for exception tracking.
125
127
  test_files:
126
128
  - spec/exceptions/backends/honeybadger/integration_spec.rb
129
+ - spec/exceptions/backends/honeybadger_spec.rb
127
130
  - spec/exceptions/backends/logger/integration_spec.rb
131
+ - spec/exceptions/backends/multi_spec.rb
128
132
  - spec/rack/exceptions_spec.rb
129
133
  - spec/spec_helper.rb
130
134
  - spec/support/honeybadger.rb