chatterbox 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +15 -0
- data/README.markdown +1 -1
- data/Rakefile +2 -2
- data/chatterbox.gemspec +31 -16
- data/examples/example_helper.rb +13 -3
- data/examples/lib/chatterbox/exception_notification/filter_example.rb +38 -0
- data/examples/lib/chatterbox/exception_notification/presenter_example.rb +89 -0
- data/examples/lib/chatterbox/exception_notification/rails_extracter_example.rb +50 -0
- data/examples/lib/chatterbox/rails_catcher_example.rb +17 -10
- data/examples/lib/chatterbox/services/email/mailer_example.rb +54 -0
- data/examples/lib/chatterbox/services/email_example.rb +89 -0
- data/examples/lib/chatterbox/services_example.rb +0 -0
- data/examples/{chatterbox_example.rb → lib/chatterbox_example.rb} +22 -24
- data/lib/chatterbox/{notification.rb → exception_notification/extracter.rb} +23 -35
- data/lib/chatterbox/exception_notification/presenter.rb +81 -0
- data/lib/chatterbox/exception_notification/rails_extracter.rb +51 -0
- data/lib/chatterbox/exception_notification.rb +8 -0
- data/lib/chatterbox/rails_catcher.rb +11 -1
- data/lib/chatterbox/services/email/mailer.rb +28 -0
- data/lib/chatterbox/services/email/views/chatterbox/services/email/mailer/message.erb +0 -0
- data/lib/chatterbox/services/email.rb +66 -0
- data/lib/chatterbox/services.rb +4 -0
- data/lib/chatterbox.rb +21 -24
- data/todo.markdown +0 -2
- data/version.yml +2 -1
- metadata +26 -12
- data/examples/lib/chatterbox/consumers/email_consumer_example.rb +0 -65
- data/examples/lib/chatterbox/notification_example.rb +0 -147
- data/lib/consumers/email_consumer.rb +0 -64
- data/lib/consumers.rb +0 -2
@@ -1,147 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. example_helper]))
|
2
|
-
|
3
|
-
describe Chatterbox::Notification do
|
4
|
-
|
5
|
-
before do
|
6
|
-
Chatterbox.logger = Logger.new(nil)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "creating the notice" do
|
10
|
-
|
11
|
-
it "should safely handle nil" do
|
12
|
-
lambda {
|
13
|
-
Chatterbox::Notification.new(nil).notice
|
14
|
-
}.should_not raise_error
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should use to_hash if message is not an exception and it responds_to possible" do
|
18
|
-
some_object = mock(:to_hash => {:foo => "bar"})
|
19
|
-
Chatterbox::Notification.new(some_object).notice.should include({:foo => "bar"})
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should call to_s on anything that responds to it, as a last resort" do
|
23
|
-
some_object = mock(:to_s => "my to_s")
|
24
|
-
Chatterbox::Notification.new(some_object).notice.should include({:summary => "my to_s"})
|
25
|
-
end
|
26
|
-
|
27
|
-
it "merges hash passed in with default info" do
|
28
|
-
hash = {:message => "hey!"}
|
29
|
-
default_info = mock()
|
30
|
-
default_info.expects(:merge).with(hash)
|
31
|
-
notification = Chatterbox::Notification.new(hash)
|
32
|
-
notification.expects(:default_info).returns(default_info)
|
33
|
-
notification.notice
|
34
|
-
end
|
35
|
-
|
36
|
-
it "turns string notice into a hash keyed by notice" do
|
37
|
-
notification = Chatterbox::Notification.new("You have been placed on alert")
|
38
|
-
notification.notice.should include({:summary => "You have been placed on alert"})
|
39
|
-
end
|
40
|
-
|
41
|
-
it "always includes a summary" do
|
42
|
-
Chatterbox::Notification.new().notice.should include(:summary)
|
43
|
-
Chatterbox::Notification.new({}).notice.should include(:summary)
|
44
|
-
Chatterbox::Notification.new(RuntimeError.new).notice.should include(:summary)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should set summary to N/A if nothing provided" do
|
48
|
-
Chatterbox::Notification.new({}).notice.should include(:summary => "N/A")
|
49
|
-
Chatterbox::Notification.new({:foo => 'baz'}).notice.should include(:summary => "N/A")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "exceptions" do
|
54
|
-
|
55
|
-
def raised_exception
|
56
|
-
raise RuntimeError, "Your zing bats got mixed up with the snosh frazzles."
|
57
|
-
rescue => e
|
58
|
-
e
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should extract exception info" do
|
62
|
-
exception = raised_exception
|
63
|
-
data = Chatterbox::Notification.new(exception).notice
|
64
|
-
data[:summary].should == "RuntimeError: Your zing bats got mixed up with the snosh frazzles."
|
65
|
-
data[:error_class].should == "RuntimeError"
|
66
|
-
data[:error_message].should == "Your zing bats got mixed up with the snosh frazzles."
|
67
|
-
data[:backtrace].should == exception.backtrace
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should extract exception info from an exception in a hash" do
|
71
|
-
exception = raised_exception
|
72
|
-
data = Chatterbox::Notification.new(:exception => exception, :other_info => "yo dawg").notice
|
73
|
-
data[:summary].should == "RuntimeError: Your zing bats got mixed up with the snosh frazzles."
|
74
|
-
data[:error_class].should == "RuntimeError"
|
75
|
-
data[:error_message].should == "Your zing bats got mixed up with the snosh frazzles."
|
76
|
-
data[:backtrace].should == exception.backtrace
|
77
|
-
data[:other_info].should == "yo dawg"
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should let extra data win over auto extracted exception data" do
|
81
|
-
exception = raised_exception
|
82
|
-
data = Chatterbox::Notification.new(:exception => exception, :summary => "I know what I'm doing, and we got an error").notice
|
83
|
-
data[:summary].should == "I know what I'm doing, and we got an error"
|
84
|
-
end
|
85
|
-
|
86
|
-
it "merges rails info and ruby info into the exception info" do
|
87
|
-
notification = Chatterbox::Notification.new(raised_exception)
|
88
|
-
rails = stub_everything(:version => "2.0", :root => "/rails/root", :env => "production")
|
89
|
-
notification.stubs(:rails_configuration).returns(rails)
|
90
|
-
notification.notice.should include(:rails_version => "2.0")
|
91
|
-
notification.notice.should include(:rails_root => "/rails/root")
|
92
|
-
notification.notice.should include(:rails_env => "production")
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "hashes" do
|
98
|
-
|
99
|
-
it "merges rails info and ruby info into the notification" do
|
100
|
-
notification = Chatterbox::Notification.new({})
|
101
|
-
rails = stub_everything(:version => "2.0", :root => "/rails/root", :env => "production")
|
102
|
-
notification.stubs(:rails_configuration).returns(rails)
|
103
|
-
notification.notice.should include(:rails_version => "2.0")
|
104
|
-
notification.notice.should include(:rails_root => "/rails/root")
|
105
|
-
notification.notice.should include(:rails_env => "production")
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
describe "default info to be included with every notification" do
|
111
|
-
|
112
|
-
it "should return full ENV" do
|
113
|
-
environment = { "USER" => "jdoe", "PATH" => "/usr/bin", "HOME" => "/usr/home/jdoe" }
|
114
|
-
notification = Chatterbox::Notification.new
|
115
|
-
notification.stubs(:env).returns(environment)
|
116
|
-
notification.default_info.should include(:environment => environment)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should return Ruby version and platform" do
|
120
|
-
notification = Chatterbox::Notification.new
|
121
|
-
notification.stubs(:ruby_version).returns("1.8.6")
|
122
|
-
notification.stubs(:ruby_platform).returns("Mac OS X blah")
|
123
|
-
data = notification.default_info
|
124
|
-
data.should include(:ruby_version => "1.8.6")
|
125
|
-
data.should include(:ruby_platform => "Mac OS X blah")
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "when Rails is defined" do
|
129
|
-
|
130
|
-
it "should return Rails info" do
|
131
|
-
notification = Chatterbox::Notification.new
|
132
|
-
rails = stub
|
133
|
-
rails.stubs(:root).returns("/some/path")
|
134
|
-
rails.stubs(:env).returns("production")
|
135
|
-
rails.stubs(:version).returns("2.1.2")
|
136
|
-
notification.stubs(:rails_configuration).returns(rails)
|
137
|
-
|
138
|
-
notification.default_info.should include(:rails_root => "/some/path")
|
139
|
-
notification.default_info.should include(:rails_env => "production")
|
140
|
-
notification.default_info.should include(:rails_version => "2.1.2")
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Chatterbox
|
2
|
-
class EmailConsumer
|
3
|
-
|
4
|
-
attr_reader :notice
|
5
|
-
|
6
|
-
def initialize(notice)
|
7
|
-
@notice = notice
|
8
|
-
end
|
9
|
-
|
10
|
-
def process
|
11
|
-
Chatterbox.logger.debug { "Mailing notification #{notice[:summary]}"}
|
12
|
-
Mailer.deliver_exception_notification(notice)
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
# Things taken out of the hash for exception emails:
|
18
|
-
#
|
19
|
-
# :details => a hash of details about the context of the error -- ie current state, request info, etc...any info
|
20
|
-
# related to the exception that is domain specific
|
21
|
-
# :error_class => taken from the Exception
|
22
|
-
# :error_message => taken from the Exception
|
23
|
-
# :backtrace => taken from the Exception
|
24
|
-
class Mailer < ActionMailer::Base
|
25
|
-
@@sender_address = %("Exception Notifier" <exception.notifier@default.com>)
|
26
|
-
cattr_accessor :sender_address
|
27
|
-
|
28
|
-
@@exception_recipients = []
|
29
|
-
cattr_accessor :exception_recipients
|
30
|
-
|
31
|
-
@@email_prefix = "[ERROR] "
|
32
|
-
cattr_accessor :email_prefix
|
33
|
-
|
34
|
-
self.template_root = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. views]))
|
35
|
-
|
36
|
-
def self.reloadable?() false end
|
37
|
-
|
38
|
-
def exception_notification(data={})
|
39
|
-
data = data.dup.symbolize_keys
|
40
|
-
|
41
|
-
content_type "text/plain"
|
42
|
-
|
43
|
-
subject "#{email_prefix} Error - #{data.delete(:summary)}"
|
44
|
-
|
45
|
-
recipients exception_recipients
|
46
|
-
from sender_address
|
47
|
-
|
48
|
-
body data
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def sanitize_backtrace(trace)
|
54
|
-
re = Regexp.new(/^#{Regexp.escape(rails_root)}/)
|
55
|
-
trace.map { |line| Pathname.new(line.gsub(re, "[RAILS_ROOT]")).cleanpath.to_s }
|
56
|
-
end
|
57
|
-
|
58
|
-
def rails_root
|
59
|
-
@rails_root ||= Pathname.new(RAILS_ROOT).cleanpath.to_s
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
data/lib/consumers.rb
DELETED