errorinbox 0.0.1a → 0.0.2a

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.
@@ -4,7 +4,7 @@ require "json"
4
4
  module ErrorInbox
5
5
  class Notifier
6
6
  def initialize(options)
7
- @options = options
7
+ @options = options.dup
8
8
  end
9
9
 
10
10
  def save(ex)
@@ -39,34 +39,31 @@ module ErrorInbox
39
39
  :message => ex.message,
40
40
  :backtrace => ex.backtrace.join("\n"),
41
41
  :environmentName => ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development",
42
+ :environment => {},
42
43
  :occurredAt => Time.now.xmlschema
43
44
  }
44
45
 
45
- if rack_env
46
+ rack_env = @options.delete(:rack_env)
47
+ if rack_env.respond_to?(:each)
46
48
  require "rack"
47
49
  body[:request] = { :url => ::Rack::Request.new(rack_env).url }
48
50
 
49
- body[:environment] = {}
50
51
  rack_env.each do |key, value|
51
52
  body[:environment][key] = value.to_s
52
53
  end
53
54
 
54
- if rack_session
55
+ if rack_session = rack_env["rack.session"]
55
56
  rack_session.each do |key, value|
56
57
  body[:session][key] = value.to_s
57
- end
58
+ end if rack_session.respond_to?(:each)
58
59
  end
59
60
  end
60
61
 
61
- JSON.dump(body)
62
- end
63
-
64
- def rack_env
65
- @rack_env ||= @options[:rack_env] if @options[:rack_env].respond_to?(:each)
66
- end
62
+ @options.each do |key, value|
63
+ body[:environment][key] = value
64
+ end
67
65
 
68
- def rack_session
69
- @rack_session ||= rack_env["rack.session"] if rack_env["rack.session"].respond_to?(:each)
66
+ JSON.dump(body)
70
67
  end
71
68
  end
72
69
  end
@@ -1,3 +1,3 @@
1
1
  module ErrorInbox
2
- VERSION = "0.0.1a"
2
+ VERSION = "0.0.2a"
3
3
  end
@@ -9,12 +9,44 @@ describe ErrorInbox::Notifier do
9
9
  end
10
10
  end
11
11
 
12
- it "sends rack exceptions" do
12
+ it "raises an error if credentials are missing" do
13
+ ErrorInbox.stub(:configuration => double("configuration", :username => nil, :password => nil))
14
+
15
+ notifier = described_class.new(:rack_env => { :foo => "bar" })
16
+ expect { notifier.save(ex) }.to raise_error(ErrorInbox::MissingCredentialsError)
17
+ end
18
+
19
+ it "raises an error if credentials are invalid" do
13
20
  ErrorInbox.stub(:configuration => double("configuration", :username => "foo", :password => "bar"))
14
21
 
22
+ stub_forbidden_request
23
+
24
+ notifier = described_class.new(:rack_env => { :foo => "bar" })
25
+ expect { notifier.save(ex) }.to raise_error(ErrorInbox::InvalidCredentialsError)
26
+ end
27
+
28
+ it "sends rack exception" do
29
+ ErrorInbox.stub(:configuration => double("configuration", :username => "foo", :password => "bar"))
30
+
31
+ stub_created_request_for_rack_exception
32
+
33
+ notifier = described_class.new(:rack_env => { :foo => "bar" })
34
+ expect(notifier.save(ex)).to eq(1)
35
+ end
36
+
37
+ it "sends any exception" do
38
+ ErrorInbox.stub(:configuration => double("configuration", :username => "foo", :password => "bar"))
39
+
40
+ stub_created_request_for_any_exception
41
+
42
+ notifier = described_class.new(:sidekiq => { :queue => "default" })
43
+ expect(notifier.save(ex)).to eq(1)
44
+ end
45
+
46
+ def stub_created_request_for_rack_exception
15
47
  stub_request(:post, "http://foo:bar@oops.errorinbox.com").
16
48
  with(
17
- :body => "{\"type\":\"RSpec::Mocks::Mock\",\"message\":\"some message\",\"backtrace\":\"a.rb:10\\nb.rb:11\",\"environmentName\":null,\"occurredAt\":\"2013-08-21T11:57:00-03:00\",\"request\":{\"url\":\"://::0\"},\"environment\":{\"foo\":\"bar\"}}",
49
+ :body => "{\"type\":\"RSpec::Mocks::Mock\",\"message\":\"some message\",\"backtrace\":\"a.rb:10\\nb.rb:11\",\"environmentName\":\"development\",\"environment\":{\"foo\":\"bar\"},\"occurredAt\":\"2013-08-21T11:57:00-03:00\",\"request\":{\"url\":\"://::0\"}}",
18
50
  :headers => { "Content-Type" => "application/json" }
19
51
  ).
20
52
  to_return(
@@ -22,24 +54,25 @@ describe ErrorInbox::Notifier do
22
54
  :body => "{\"id\":1}",
23
55
  :headers => { "Content-Type" => "application/json" }
24
56
  )
25
-
26
- notifier = described_class.new(:rack_env => { :foo => "bar" })
27
- expect(notifier.save(ex)).to eq(1)
28
57
  end
29
58
 
30
- it "raises an error if credentials are missing" do
31
- ErrorInbox.stub(:configuration => double("configuration", :username => nil, :password => nil))
32
-
33
- notifier = described_class.new(:rack_env => { :foo => "bar" })
34
- expect { notifier.save(ex) }.to raise_error(ErrorInbox::MissingCredentialsError)
59
+ def stub_created_request_for_any_exception
60
+ stub_request(:post, "http://foo:bar@oops.errorinbox.com").
61
+ with(
62
+ :body => "{\"type\":\"RSpec::Mocks::Mock\",\"message\":\"some message\",\"backtrace\":\"a.rb:10\\nb.rb:11\",\"environmentName\":\"development\",\"environment\":{\"sidekiq\":{\"queue\":\"default\"}},\"occurredAt\":\"2013-08-21T11:57:00-03:00\"}",
63
+ :headers => { "Content-Type" => "application/json" }
64
+ ).
65
+ to_return(
66
+ :status => 201,
67
+ :body => "{\"id\":1}",
68
+ :headers => { "Content-Type" => "application/json" }
69
+ )
35
70
  end
36
71
 
37
- it "raises an error if credentials are invalid" do
38
- ErrorInbox.stub(:configuration => double("configuration", :username => "foo", :password => "bar"))
39
-
72
+ def stub_forbidden_request
40
73
  stub_request(:post, "http://foo:bar@oops.errorinbox.com").
41
74
  with(
42
- :body => "{\"type\":\"RSpec::Mocks::Mock\",\"message\":\"some message\",\"backtrace\":\"a.rb:10\\nb.rb:11\",\"environmentName\":null,\"occurredAt\":\"2013-08-21T11:57:00-03:00\",\"request\":{\"url\":\"://::0\"},\"environment\":{\"foo\":\"bar\"}}",
75
+ :body => "{\"type\":\"RSpec::Mocks::Mock\",\"message\":\"some message\",\"backtrace\":\"a.rb:10\\nb.rb:11\",\"environmentName\":\"development\",\"environment\":{\"foo\":\"bar\"},\"occurredAt\":\"2013-08-21T11:57:00-03:00\",\"request\":{\"url\":\"://::0\"}}",
43
76
  :headers => { 'Content-Type'=>'application/json' }
44
77
  ).
45
78
  to_return(
@@ -47,8 +80,5 @@ describe ErrorInbox::Notifier do
47
80
  :body => "{\"error\":\"forbidden\"}",
48
81
  :headers => { "Content-Type" => "application/json" }
49
82
  )
50
-
51
- notifier = described_class.new(:rack_env => { :foo => "bar" })
52
- expect { notifier.save(ex) }.to raise_error(ErrorInbox::InvalidCredentialsError)
53
83
  end
54
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errorinbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1a
4
+ version: 0.0.2a
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -82,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  segments:
84
84
  - 0
85
- hash: -1940987844180716958
85
+ hash: -231840207079135962
86
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  none: false
88
88
  requirements: