errorinbox 0.0.5a → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89adea7fd26b7749808bc4642f3948cfb058b964
4
- data.tar.gz: df27ea8e1939e6a37a8d25b54e7bcefe69ec16c6
3
+ metadata.gz: f08056c5e1cf6d6a2e44c6975ebc3b2bf0c18ae3
4
+ data.tar.gz: e0eb73759a28cc103b4c0caa0c8f6c5e0ca00701
5
5
  SHA512:
6
- metadata.gz: caa210c6b4980f19827cd5734ccdc14354909a1612f402a5d2408d69d55a4fc80a2389153cbe26b4caf675d5ca46597f167e6fef45f537038d9585b68b84a3e2
7
- data.tar.gz: 88d6f364deaa6b7e15636d2ac65ae83853fa31f616c82b32a3298aacabf8a4db5c13059a39b71e7ac72f48c81d384360ecd0a46f4e574045d489d310ba1684c5
6
+ metadata.gz: f90fd70d5100bf8603ce1e1b3755fc348cc2819263c2527f8f465f607e7638680cee551e2946adca031a76bb949036ffe546cca177b4a161225b3e0694f1110d
7
+ data.tar.gz: 53f0bb3ae6fa6db265f8343a0b773ebdd509f409cbe0d68794050ae1c9cbcd0ed34ef8bc924ce4dc5fce777a4a48cec9d202e0489176fc87e7308f5471948740
@@ -3,6 +3,14 @@ module ErrorInbox
3
3
  attr_accessor :username, :password
4
4
  attr_writer :logger
5
5
 
6
+ def ignore_if(&block)
7
+ ignores << block
8
+ end
9
+
10
+ def ignores
11
+ @ignores ||= []
12
+ end
13
+
6
14
  def logger
7
15
  @logger ||= begin
8
16
  require "logger"
@@ -20,11 +20,16 @@ module ErrorInbox
20
20
  end
21
21
 
22
22
  def save(ex)
23
- if ErrorInbox.configuration.username && ErrorInbox.configuration.password
23
+ if configuration.username && configuration.password
24
+ if ignored?(ex)
25
+ configuration.logger.info("#{ex.class.name}: ignored")
26
+ return {}
27
+ end
28
+
24
29
  response = begin
25
30
  http_request(prepare_body(ex))
26
31
  rescue *HTTP_ERRORS => ex
27
- ErrorInbox.configuration.logger.error("#{ex.class.name}: #{ex.message}")
32
+ configuration.logger.error("#{ex.class.name}: #{ex.message}")
28
33
  nil
29
34
  end
30
35
 
@@ -32,17 +37,21 @@ module ErrorInbox
32
37
  when Net::HTTPCreated
33
38
  JSON.load(response.body)["id"]
34
39
  else
35
- ErrorInbox.configuration.logger.error(response.class.name)
40
+ configuration.logger.error(response.class.name)
36
41
  {}
37
42
  end
38
43
  else
39
- ErrorInbox.configuration.logger.error("Missing credentials configuration")
44
+ configuration.logger.error("Missing credentials configuration")
40
45
  {}
41
46
  end
42
47
  end
43
48
 
44
49
  protected
45
50
 
51
+ def ignored?(ex)
52
+ !!configuration.ignores.find { |blk| blk.call(ex, @options) }
53
+ end
54
+
46
55
  def prepare_body(ex)
47
56
  body = {
48
57
  :type => ex.class.name,
@@ -86,8 +95,12 @@ module ErrorInbox
86
95
  request = Net::HTTP::Post.new(uri.request_uri)
87
96
  request["Content-Type"] = "application/json"
88
97
  request.body = body
89
- request.basic_auth(ErrorInbox.configuration.username, ErrorInbox.configuration.password)
98
+ request.basic_auth(configuration.username, configuration.password)
90
99
  http.request(request)
91
100
  end
101
+
102
+ def configuration
103
+ ErrorInbox.configuration
104
+ end
92
105
  end
93
106
  end
@@ -1,3 +1,3 @@
1
1
  module ErrorInbox
2
- VERSION = "0.0.5a"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe ErrorInbox::Configuration do
4
+ it "appends the block in the ignores attribute" do
5
+ expect { subject.ignore_if { true } }.to change{ subject.ignores.size }.from(0).to(1)
6
+ end
7
+ end
@@ -2,6 +2,8 @@ require "spec_helper"
2
2
 
3
3
  describe ErrorInbox::Notifier do
4
4
  let(:ex) { double("exception", :message => "some message", :backtrace => ["a.rb:10", "b.rb:11"]) }
5
+ let(:configuration) { double("configuration", :username => nil, :password => nil, :ignores => []) }
6
+ let(:logger) { double("logger") }
5
7
 
6
8
  around do |example|
7
9
  Timecop.travel(2013, 8, 21, 11, 57, 0) do
@@ -10,7 +12,8 @@ describe ErrorInbox::Notifier do
10
12
  end
11
13
 
12
14
  it "raises an error if credentials are missing" do
13
- ErrorInbox.stub(:configuration => double("configuration", :username => nil, :password => nil, :logger => logger = double("logger")))
15
+ ErrorInbox.stub(:configuration => configuration)
16
+ configuration.stub(:logger => logger)
14
17
  logger.
15
18
  should_receive(:error).
16
19
  with("Missing credentials configuration")
@@ -20,7 +23,8 @@ describe ErrorInbox::Notifier do
20
23
  end
21
24
 
22
25
  it "raises an error if credentials are invalid" do
23
- ErrorInbox.stub(:configuration => double("configuration", :username => "foo", :password => "bar", :logger => logger = double("logger")))
26
+ ErrorInbox.stub(:configuration => configuration)
27
+ configuration.stub(:username => "foo", :password => "bar", :logger => logger)
24
28
  logger.
25
29
  should_receive(:error).
26
30
  with("Net::HTTPForbidden")
@@ -31,22 +35,36 @@ describe ErrorInbox::Notifier do
31
35
  expect(notifier.save(ex)).to eq({})
32
36
  end
33
37
 
34
- it "sends rack exception" do
35
- ErrorInbox.stub(:configuration => double("configuration", :username => "foo", :password => "bar"))
38
+ context "with valid credentials" do
39
+ before do
40
+ configuration.stub(:username => "foo", :password => "bar")
36
41
 
37
- stub_created_request_for_rack_exception
42
+ ErrorInbox.stub(:configuration => configuration)
43
+ end
38
44
 
39
- notifier = described_class.new(:rack_env => { :foo => "bar" })
40
- expect(notifier.save(ex)).to eq(1)
41
- end
45
+ it "sends rack exception" do
46
+ stub_created_request_for_rack_exception
47
+
48
+ notifier = described_class.new(:rack_env => { :foo => "bar" })
49
+ expect(notifier.save(ex)).to eq(1)
50
+ end
51
+
52
+ it "sends any other exception" do
53
+ stub_created_request_for_any_exception
42
54
 
43
- it "sends any exception" do
44
- ErrorInbox.stub(:configuration => double("configuration", :username => "foo", :password => "bar"))
55
+ notifier = described_class.new(:sidekiq => { :queue => "default" })
56
+ expect(notifier.save(ex)).to eq(1)
57
+ end
45
58
 
46
- stub_created_request_for_any_exception
59
+ it "does not send ignored exceptions" do
60
+ configuration.stub(:ignores => [proc{ |ex, o| true }], :logger => logger)
61
+ logger.
62
+ should_receive(:info).
63
+ with("RSpec::Mocks::Mock: ignored")
47
64
 
48
- notifier = described_class.new(:sidekiq => { :queue => "default" })
49
- expect(notifier.save(ex)).to eq(1)
65
+ notifier = described_class.new(:rack_env => { :foo => "bar" })
66
+ expect(notifier.save(ex)).to eq({})
67
+ end
50
68
  end
51
69
 
52
70
  def stub_created_request_for_rack_exception
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errorinbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5a
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Souza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-26 00:00:00.000000000 Z
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,6 +58,7 @@ files:
58
58
  - lib/error_inbox/rack.rb
59
59
  - lib/error_inbox/version.rb
60
60
  - lib/errorinbox.rb
61
+ - spec/error_inbox/configuration_spec.rb
61
62
  - spec/error_inbox/notifier_spec.rb
62
63
  - spec/error_inbox/rack_spec.rb
63
64
  - spec/error_inbox_spec.rb
@@ -77,9 +78,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
78
  version: '0'
78
79
  required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  requirements:
80
- - - '>'
81
+ - - '>='
81
82
  - !ruby/object:Gem::Version
82
- version: 1.3.1
83
+ version: '0'
83
84
  requirements: []
84
85
  rubyforge_project:
85
86
  rubygems_version: 2.0.3
@@ -87,6 +88,7 @@ signing_key:
87
88
  specification_version: 4
88
89
  summary: Capture and send all exceptions raised by your app to errorinbox.com
89
90
  test_files:
91
+ - spec/error_inbox/configuration_spec.rb
90
92
  - spec/error_inbox/notifier_spec.rb
91
93
  - spec/error_inbox/rack_spec.rb
92
94
  - spec/error_inbox_spec.rb