errornot_notifier 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/INSTALL +8 -8
- data/README.rdoc +63 -53
- data/Rakefile +92 -8
- data/TESTING.rdoc +1 -1
- data/generators/{hoptoad/hoptoad_generator.rb → errornot/errornot_generator.rb} +6 -6
- data/generators/{hoptoad → errornot}/lib/insert_commands.rb +0 -0
- data/generators/{hoptoad → errornot}/lib/rake_commands.rb +0 -0
- data/generators/errornot/templates/capistrano_hook.rb +6 -0
- data/generators/errornot/templates/errornot_notifier_tasks.rake +5 -0
- data/generators/{hoptoad → errornot}/templates/initializer.rb +2 -2
- data/lib/{hoptoad_notifier → errornot_notifier}/backtrace.rb +1 -1
- data/lib/errornot_notifier/capistrano.rb +20 -0
- data/lib/{hoptoad_notifier → errornot_notifier}/configuration.rb +14 -16
- data/lib/{hoptoad_notifier → errornot_notifier}/notice.rb +2 -2
- data/lib/{hoptoad_notifier → errornot_notifier}/rack.rb +8 -8
- data/lib/{hoptoad_notifier → errornot_notifier}/rails/action_controller_catcher.rb +9 -9
- data/lib/{hoptoad_notifier → errornot_notifier}/rails/controller_methods.rb +15 -15
- data/lib/{hoptoad_notifier → errornot_notifier}/rails/error_lookup.rb +9 -9
- data/lib/{hoptoad_notifier → errornot_notifier}/rails.rb +11 -11
- data/lib/{hoptoad_notifier → errornot_notifier}/sender.rb +8 -8
- data/lib/{hoptoad_notifier → errornot_notifier}/tasks.rb +19 -19
- data/lib/errornot_notifier/version.rb +3 -0
- data/lib/{hoptoad_notifier.rb → errornot_notifier.rb} +20 -20
- data/lib/{hoptoad_tasks.rb → errornot_tasks.rb} +9 -7
- data/lib/templates/rescue.erb +5 -5
- data/rails/init.rb +1 -1
- data/script/integration_test.rb +6 -6
- data/test/backtrace_test.rb +16 -16
- data/test/catcher_test.rb +22 -22
- data/test/configuration_test.rb +21 -23
- data/test/erronot_tasks_test.rb +147 -0
- data/test/helper.rb +16 -15
- data/test/logger_test.rb +12 -10
- data/test/notice_test.rb +9 -9
- data/test/notifier_test.rb +30 -30
- data/test/rack_test.rb +7 -7
- data/test/rails_initializer_test.rb +8 -8
- data/test/sender_test.rb +13 -12
- metadata +73 -53
- data/generators/hoptoad/templates/capistrano_hook.rb +0 -6
- data/generators/hoptoad/templates/hoptoad_notifier_tasks.rake +0 -5
- data/lib/hoptoad_notifier/capistrano.rb +0 -20
- data/lib/hoptoad_notifier/version.rb +0 -3
- data/test/hoptoad_tasks_test.rb +0 -138
data/test/helper.rb
CHANGED
@@ -19,7 +19,7 @@ require 'active_support'
|
|
19
19
|
require 'nokogiri'
|
20
20
|
require 'rack'
|
21
21
|
|
22
|
-
require "
|
22
|
+
require "errornot_notifier"
|
23
23
|
|
24
24
|
begin require 'redgreen'; rescue LoadError; end
|
25
25
|
|
@@ -29,7 +29,7 @@ module TestMethods
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def do_raise
|
32
|
-
raise "
|
32
|
+
raise "Errornot"
|
33
33
|
end
|
34
34
|
|
35
35
|
def do_not_raise
|
@@ -45,17 +45,17 @@ module TestMethods
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def manual_notify
|
48
|
-
|
48
|
+
notify_errornot(Exception.new)
|
49
49
|
render :text => "Success"
|
50
50
|
end
|
51
51
|
|
52
52
|
def manual_notify_ignored
|
53
|
-
|
53
|
+
notify_errornot(ActiveRecord::RecordNotFound.new("404"))
|
54
54
|
render :text => "Success"
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
class
|
58
|
+
class ErrornotController < ActionController::Base
|
59
59
|
include TestMethods
|
60
60
|
end
|
61
61
|
|
@@ -96,11 +96,11 @@ class Test::Unit::TestCase
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def stub_sender
|
99
|
-
stub('sender', :
|
99
|
+
stub('sender', :send_to_errornot => nil)
|
100
100
|
end
|
101
101
|
|
102
102
|
def stub_sender!
|
103
|
-
|
103
|
+
ErrornotNotifier.sender = stub_sender
|
104
104
|
end
|
105
105
|
|
106
106
|
def stub_notice
|
@@ -109,23 +109,24 @@ class Test::Unit::TestCase
|
|
109
109
|
|
110
110
|
def stub_notice!
|
111
111
|
returning stub_notice do |notice|
|
112
|
-
|
112
|
+
ErrornotNotifier::Notice.stubs(:new => notice)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
116
|
def create_dummy
|
117
|
-
|
117
|
+
ErrornotNotifier::DummySender.new
|
118
118
|
end
|
119
119
|
|
120
120
|
def reset_config
|
121
|
-
|
122
|
-
|
121
|
+
ErrornotNotifier.configuration = nil
|
122
|
+
ErrornotNotifier.configure do |config|
|
123
|
+
config.host = "localhost"
|
123
124
|
config.api_key = 'abc123'
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
127
128
|
def clear_backtrace_filters
|
128
|
-
|
129
|
+
ErrornotNotifier.configuration.backtrace_filters.clear
|
129
130
|
end
|
130
131
|
|
131
132
|
def build_exception
|
@@ -155,11 +156,11 @@ class Test::Unit::TestCase
|
|
155
156
|
end
|
156
157
|
|
157
158
|
def assert_caught_and_sent
|
158
|
-
assert !
|
159
|
+
assert !ErrornotNotifier.sender.collected.empty?
|
159
160
|
end
|
160
161
|
|
161
162
|
def assert_caught_and_not_sent
|
162
|
-
assert
|
163
|
+
assert ErrornotNotifier.sender.collected.empty?
|
163
164
|
end
|
164
165
|
|
165
166
|
def assert_array_starts_with(expected, actual)
|
@@ -217,7 +218,7 @@ class CollectingSender
|
|
217
218
|
@collected = []
|
218
219
|
end
|
219
220
|
|
220
|
-
def
|
221
|
+
def send_to_errornot(data)
|
221
222
|
@collected << data
|
222
223
|
end
|
223
224
|
end
|
data/test/logger_test.rb
CHANGED
@@ -11,27 +11,29 @@ class LoggerTest < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def send_notice
|
14
|
-
|
14
|
+
ErrornotNotifier.sender.send_to_errornot('data')
|
15
15
|
end
|
16
16
|
|
17
17
|
def stub_verbose_log
|
18
|
-
|
18
|
+
ErrornotNotifier.stubs(:write_verbose_log)
|
19
19
|
end
|
20
20
|
|
21
21
|
def assert_logged(expected)
|
22
|
-
assert_received(
|
22
|
+
assert_received(ErrornotNotifier, :write_verbose_log) do |expect|
|
23
23
|
expect.with {|actual| actual =~ expected }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def assert_not_logged(expected)
|
28
|
-
assert_received(
|
28
|
+
assert_received(ErrornotNotifier, :write_verbose_log) do |expect|
|
29
29
|
expect.with {|actual| actual =~ expected }.never
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
def configure
|
34
|
-
|
34
|
+
ErrornotNotifier.configure { |config|
|
35
|
+
config.host = "localhost"
|
36
|
+
}
|
35
37
|
end
|
36
38
|
|
37
39
|
should "report that notifier is ready when configured" do
|
@@ -42,7 +44,7 @@ class LoggerTest < Test::Unit::TestCase
|
|
42
44
|
|
43
45
|
should "not report that notifier is ready when internally configured" do
|
44
46
|
stub_verbose_log
|
45
|
-
|
47
|
+
ErrornotNotifier.configure(true) { |config| }
|
46
48
|
assert_not_logged /.*/
|
47
49
|
end
|
48
50
|
|
@@ -52,7 +54,7 @@ class LoggerTest < Test::Unit::TestCase
|
|
52
54
|
stub_http(Net::HTTPSuccess)
|
53
55
|
send_notice
|
54
56
|
assert_logged /Environment Info:/
|
55
|
-
assert_not_logged /Response from
|
57
|
+
assert_not_logged /Response from Errornot:/
|
56
58
|
end
|
57
59
|
|
58
60
|
should "print environment info on a failed notification without a body" do
|
@@ -61,7 +63,7 @@ class LoggerTest < Test::Unit::TestCase
|
|
61
63
|
stub_http(Net::HTTPError)
|
62
64
|
send_notice
|
63
65
|
assert_logged /Environment Info:/
|
64
|
-
assert_not_logged /Response from
|
66
|
+
assert_not_logged /Response from Errornot:/
|
65
67
|
end
|
66
68
|
|
67
69
|
should "print environment info and response on a success with a body" do
|
@@ -70,7 +72,7 @@ class LoggerTest < Test::Unit::TestCase
|
|
70
72
|
stub_http(Net::HTTPSuccess, 'test')
|
71
73
|
send_notice
|
72
74
|
assert_logged /Environment Info:/
|
73
|
-
assert_logged /Response from
|
75
|
+
assert_logged /Response from Errornot:/
|
74
76
|
end
|
75
77
|
|
76
78
|
should "print environment info and response on a failure with a body" do
|
@@ -79,7 +81,7 @@ class LoggerTest < Test::Unit::TestCase
|
|
79
81
|
stub_http(Net::HTTPError, 'test')
|
80
82
|
send_notice
|
81
83
|
assert_logged /Environment Info:/
|
82
|
-
assert_logged /Response from
|
84
|
+
assert_logged /Response from Errornot:/
|
83
85
|
end
|
84
86
|
|
85
87
|
end
|
data/test/notice_test.rb
CHANGED
@@ -5,14 +5,14 @@ class NoticeTest < Test::Unit::TestCase
|
|
5
5
|
include DefinesConstants
|
6
6
|
|
7
7
|
def configure
|
8
|
-
returning
|
8
|
+
returning ErrornotNotifier::Configuration.new do |config|
|
9
9
|
config.api_key = 'abc123def456'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def build_notice(args = {})
|
14
14
|
configuration = args.delete(:configuration) || configure
|
15
|
-
|
15
|
+
ErrornotNotifier::Notice.new(configuration.merge(args))
|
16
16
|
end
|
17
17
|
|
18
18
|
def stub_request(attrs = {})
|
@@ -59,7 +59,7 @@ class NoticeTest < Test::Unit::TestCase
|
|
59
59
|
array = ["user.rb:34:in `crazy'"]
|
60
60
|
exception = build_exception
|
61
61
|
exception.set_backtrace array
|
62
|
-
backtrace =
|
62
|
+
backtrace = ErrornotNotifier::Backtrace.parse(array)
|
63
63
|
notice_from_exception = build_notice(:exception => exception)
|
64
64
|
|
65
65
|
|
@@ -77,9 +77,9 @@ class NoticeTest < Test::Unit::TestCase
|
|
77
77
|
backtrace_array = ['my/file/backtrace:3']
|
78
78
|
exception = build_exception
|
79
79
|
exception.set_backtrace(backtrace_array)
|
80
|
-
|
80
|
+
ErrornotNotifier::Backtrace.expects(:parse).with(backtrace_array, {:filters => 'foo'})
|
81
81
|
|
82
|
-
notice =
|
82
|
+
notice = ErrornotNotifier::Notice.new({:exception => exception, :backtrace_filters => 'foo'})
|
83
83
|
end
|
84
84
|
|
85
85
|
should "set the error class from an exception or hash" do
|
@@ -133,7 +133,7 @@ class NoticeTest < Test::Unit::TestCase
|
|
133
133
|
end
|
134
134
|
|
135
135
|
should "set sensible defaults without an exception" do
|
136
|
-
backtrace =
|
136
|
+
backtrace = ErrornotNotifier::Backtrace.parse(build_backtrace_array)
|
137
137
|
notice = build_notice(:backtrace => build_backtrace_array)
|
138
138
|
|
139
139
|
assert_equal 'Notification', notice.error_message
|
@@ -143,8 +143,8 @@ class NoticeTest < Test::Unit::TestCase
|
|
143
143
|
end
|
144
144
|
|
145
145
|
should "use the caller as the backtrace for an exception without a backtrace" do
|
146
|
-
filters =
|
147
|
-
backtrace =
|
146
|
+
filters = ErrornotNotifier::Configuration.new.backtrace_filters
|
147
|
+
backtrace = ErrornotNotifier::Backtrace.parse(caller, :filters => filters)
|
148
148
|
notice = build_notice(:exception => StandardError.new('error'), :backtrace => nil)
|
149
149
|
|
150
150
|
assert_array_starts_with backtrace.lines, notice.backtrace.lines
|
@@ -166,7 +166,7 @@ class NoticeTest < Test::Unit::TestCase
|
|
166
166
|
|
167
167
|
context "a Notice turned into XML" do
|
168
168
|
setup do
|
169
|
-
|
169
|
+
ErrornotNotifier.configure do |config|
|
170
170
|
config.api_key = "1234567890"
|
171
171
|
end
|
172
172
|
|
data/test/notifier_test.rb
CHANGED
@@ -16,48 +16,48 @@ class NotifierTest < Test::Unit::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def assert_sent(notice, notice_args)
|
19
|
-
assert_received(
|
19
|
+
assert_received(ErrornotNotifier::Notice, :new) {|expect| expect.with(has_entries(notice_args)) }
|
20
20
|
assert_received(notice, :to_xml)
|
21
|
-
assert_received(
|
21
|
+
assert_received(ErrornotNotifier.sender, :send_to_errornot) {|expect| expect.with(notice.to_xml) }
|
22
22
|
end
|
23
23
|
|
24
24
|
def set_public_env
|
25
|
-
|
25
|
+
ErrornotNotifier.configure { |config| config.environment_name = 'production' }
|
26
26
|
end
|
27
27
|
|
28
28
|
def set_development_env
|
29
|
-
|
29
|
+
ErrornotNotifier.configure { |config| config.environment_name = 'development' }
|
30
30
|
end
|
31
31
|
|
32
32
|
should "yield and save a configuration when configuring" do
|
33
33
|
yielded_configuration = nil
|
34
|
-
|
34
|
+
ErrornotNotifier.configure do |config|
|
35
35
|
yielded_configuration = config
|
36
36
|
end
|
37
37
|
|
38
|
-
assert_kind_of
|
39
|
-
assert_equal yielded_configuration,
|
38
|
+
assert_kind_of ErrornotNotifier::Configuration, yielded_configuration
|
39
|
+
assert_equal yielded_configuration, ErrornotNotifier.configuration
|
40
40
|
end
|
41
41
|
|
42
42
|
should "not remove existing config options when configuring twice" do
|
43
43
|
first_config = nil
|
44
|
-
|
44
|
+
ErrornotNotifier.configure do |config|
|
45
45
|
first_config = config
|
46
46
|
end
|
47
|
-
|
47
|
+
ErrornotNotifier.configure do |config|
|
48
48
|
assert_equal first_config, config
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
should "configure the sender" do
|
53
53
|
sender = stub_sender
|
54
|
-
|
54
|
+
ErrornotNotifier::Sender.stubs(:new => sender)
|
55
55
|
configuration = nil
|
56
56
|
|
57
|
-
|
57
|
+
ErrornotNotifier.configure { |yielded_config| configuration = yielded_config }
|
58
58
|
|
59
|
-
assert_received(
|
60
|
-
assert_equal sender,
|
59
|
+
assert_received(ErrornotNotifier::Sender, :new) { |expect| expect.with(configuration) }
|
60
|
+
assert_equal sender, ErrornotNotifier.sender
|
61
61
|
end
|
62
62
|
|
63
63
|
should "create and send a notice for an exception" do
|
@@ -66,7 +66,7 @@ class NotifierTest < Test::Unit::TestCase
|
|
66
66
|
stub_sender!
|
67
67
|
notice = stub_notice!
|
68
68
|
|
69
|
-
|
69
|
+
ErrornotNotifier.notify(exception)
|
70
70
|
|
71
71
|
assert_sent notice, :exception => exception
|
72
72
|
end
|
@@ -77,7 +77,7 @@ class NotifierTest < Test::Unit::TestCase
|
|
77
77
|
notice_args = { :error_message => 'uh oh' }
|
78
78
|
stub_sender!
|
79
79
|
|
80
|
-
|
80
|
+
ErrornotNotifier.notify(notice_args)
|
81
81
|
|
82
82
|
assert_sent(notice, notice_args)
|
83
83
|
end
|
@@ -89,7 +89,7 @@ class NotifierTest < Test::Unit::TestCase
|
|
89
89
|
notice_args = { :error_message => 'uh oh' }
|
90
90
|
stub_sender!
|
91
91
|
|
92
|
-
|
92
|
+
ErrornotNotifier.notify(exception, notice_args)
|
93
93
|
|
94
94
|
assert_sent(notice, notice_args.merge(:exception => exception))
|
95
95
|
end
|
@@ -98,10 +98,10 @@ class NotifierTest < Test::Unit::TestCase
|
|
98
98
|
set_development_env
|
99
99
|
sender = stub_sender!
|
100
100
|
|
101
|
-
|
102
|
-
|
101
|
+
ErrornotNotifier.notify(build_exception)
|
102
|
+
ErrornotNotifier.notify_or_ignore(build_exception)
|
103
103
|
|
104
|
-
assert_received(sender, :
|
104
|
+
assert_received(sender, :send_to_errornot) {|expect| expect.never }
|
105
105
|
end
|
106
106
|
|
107
107
|
should "not deliver an ignored exception when notifying implicitly" do
|
@@ -111,9 +111,9 @@ class NotifierTest < Test::Unit::TestCase
|
|
111
111
|
notice = stub_notice!
|
112
112
|
notice.stubs(:ignore? => true)
|
113
113
|
|
114
|
-
|
114
|
+
ErrornotNotifier.notify_or_ignore(exception)
|
115
115
|
|
116
|
-
assert_received(sender, :
|
116
|
+
assert_received(sender, :send_to_errornot) {|expect| expect.never }
|
117
117
|
end
|
118
118
|
|
119
119
|
should "deliver an ignored exception when notifying manually" do
|
@@ -123,7 +123,7 @@ class NotifierTest < Test::Unit::TestCase
|
|
123
123
|
notice = stub_notice!
|
124
124
|
notice.stubs(:ignore? => true)
|
125
125
|
|
126
|
-
|
126
|
+
ErrornotNotifier.notify(exception)
|
127
127
|
|
128
128
|
assert_sent(notice, :exception => exception)
|
129
129
|
end
|
@@ -133,11 +133,11 @@ class NotifierTest < Test::Unit::TestCase
|
|
133
133
|
config_opts = { 'one' => 'two', 'three' => 'four' }
|
134
134
|
notice = stub_notice!
|
135
135
|
stub_sender!
|
136
|
-
|
136
|
+
ErrornotNotifier.configuration = stub('config', :merge => config_opts, :public? => true)
|
137
137
|
|
138
|
-
|
138
|
+
ErrornotNotifier.notify(exception)
|
139
139
|
|
140
|
-
assert_received(
|
140
|
+
assert_received(ErrornotNotifier::Notice, :new) do |expect|
|
141
141
|
expect.with(has_entries(config_opts))
|
142
142
|
end
|
143
143
|
end
|
@@ -146,7 +146,7 @@ class NotifierTest < Test::Unit::TestCase
|
|
146
146
|
setup do
|
147
147
|
@params = { :controller => "users", :action => "create" }
|
148
148
|
@exception = build_exception
|
149
|
-
@hash =
|
149
|
+
@hash = ErrornotNotifier.build_lookup_hash_for(@exception, @params)
|
150
150
|
end
|
151
151
|
|
152
152
|
should "set action" do
|
@@ -176,14 +176,14 @@ class NotifierTest < Test::Unit::TestCase
|
|
176
176
|
should "not set file or line number with no backtrace" do
|
177
177
|
@exception.stubs(:backtrace).returns([])
|
178
178
|
|
179
|
-
@hash =
|
179
|
+
@hash = ErrornotNotifier.build_lookup_hash_for(@exception)
|
180
180
|
|
181
181
|
assert_nil @hash[:line_number]
|
182
182
|
assert_nil @hash[:file]
|
183
183
|
end
|
184
184
|
|
185
185
|
should "not set action or controller when not provided" do
|
186
|
-
@hash =
|
186
|
+
@hash = ErrornotNotifier.build_lookup_hash_for(@exception)
|
187
187
|
|
188
188
|
assert_nil @hash[:action]
|
189
189
|
assert_nil @hash[:controller]
|
@@ -199,7 +199,7 @@ class NotifierTest < Test::Unit::TestCase
|
|
199
199
|
end
|
200
200
|
|
201
201
|
should "unwrap exceptions that provide #original_exception" do
|
202
|
-
@hash =
|
202
|
+
@hash = ErrornotNotifier.build_lookup_hash_for(@exception)
|
203
203
|
assert_equal "NotifierTest::OriginalException", @hash[:error_class]
|
204
204
|
end
|
205
205
|
end
|
@@ -214,7 +214,7 @@ class NotifierTest < Test::Unit::TestCase
|
|
214
214
|
end
|
215
215
|
|
216
216
|
should "unwrap exceptions that provide #continued_exception" do
|
217
|
-
@hash =
|
217
|
+
@hash = ErrornotNotifier.build_lookup_hash_for(@exception)
|
218
218
|
assert_equal "NotifierTest::ContinuedException", @hash[:error_class]
|
219
219
|
end
|
220
220
|
end
|
data/test/rack_test.rb
CHANGED
@@ -5,7 +5,7 @@ class RackTest < Test::Unit::TestCase
|
|
5
5
|
should "call the upstream app with the environment" do
|
6
6
|
environment = { 'key' => 'value' }
|
7
7
|
app = lambda { |env| ['response', {}, env] }
|
8
|
-
stack =
|
8
|
+
stack = ErrornotNotifier::Rack.new(app)
|
9
9
|
|
10
10
|
response = stack.call(environment)
|
11
11
|
|
@@ -13,7 +13,7 @@ class RackTest < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
should "deliver an exception raised while calling an upstream app" do
|
16
|
-
|
16
|
+
ErrornotNotifier.stubs(:notify_or_ignore)
|
17
17
|
|
18
18
|
exception = build_exception
|
19
19
|
environment = { 'key' => 'value' }
|
@@ -22,7 +22,7 @@ class RackTest < Test::Unit::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
begin
|
25
|
-
stack =
|
25
|
+
stack = ErrornotNotifier::Rack.new(app)
|
26
26
|
stack.call(environment)
|
27
27
|
rescue Exception => raised
|
28
28
|
assert_equal exception, raised
|
@@ -30,13 +30,13 @@ class RackTest < Test::Unit::TestCase
|
|
30
30
|
flunk "Didn't raise an exception"
|
31
31
|
end
|
32
32
|
|
33
|
-
assert_received(
|
33
|
+
assert_received(ErrornotNotifier, :notify_or_ignore) do |expect|
|
34
34
|
expect.with(exception, :rack_env => environment)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
should "deliver an exception in rack.exception" do
|
39
|
-
|
39
|
+
ErrornotNotifier.stubs(:notify_or_ignore)
|
40
40
|
exception = build_exception
|
41
41
|
environment = { 'key' => 'value' }
|
42
42
|
|
@@ -45,12 +45,12 @@ class RackTest < Test::Unit::TestCase
|
|
45
45
|
env['rack.exception'] = exception
|
46
46
|
response
|
47
47
|
end
|
48
|
-
stack =
|
48
|
+
stack = ErrornotNotifier::Rack.new(app)
|
49
49
|
|
50
50
|
actual_response = stack.call(environment)
|
51
51
|
|
52
52
|
assert_equal response, actual_response
|
53
|
-
assert_received(
|
53
|
+
assert_received(ErrornotNotifier, :notify_or_ignore) do |expect|
|
54
54
|
expect.with(exception, :rack_env => environment)
|
55
55
|
end
|
56
56
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'errornot_notifier/rails'
|
4
4
|
|
5
5
|
class RailsInitializerTest < Test::Unit::TestCase
|
6
6
|
include DefinesConstants
|
@@ -12,25 +12,25 @@ class RailsInitializerTest < Test::Unit::TestCase
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
define_constant("Rails", rails)
|
15
|
-
|
16
|
-
assert_equal "RAILS LOGGER",
|
15
|
+
ErrornotNotifier::Rails.initialize
|
16
|
+
assert_equal "RAILS LOGGER", ErrornotNotifier.logger
|
17
17
|
end
|
18
18
|
|
19
19
|
should "trigger use of Rails' default logger if logger isn't set and Rails.logger doesn't exist" do
|
20
20
|
define_constant("RAILS_DEFAULT_LOGGER", "RAILS DEFAULT LOGGER")
|
21
21
|
|
22
|
-
|
23
|
-
assert_equal "RAILS DEFAULT LOGGER",
|
22
|
+
ErrornotNotifier::Rails.initialize
|
23
|
+
assert_equal "RAILS DEFAULT LOGGER", ErrornotNotifier.logger
|
24
24
|
end
|
25
25
|
|
26
26
|
should "allow overriding of the logger if already assigned" do
|
27
27
|
define_constant("RAILS_DEFAULT_LOGGER", "RAILS DEFAULT LOGGER")
|
28
|
-
|
28
|
+
ErrornotNotifier::Rails.initialize
|
29
29
|
|
30
|
-
|
30
|
+
ErrornotNotifier.configure(true) do |config|
|
31
31
|
config.logger = "OVERRIDDEN LOGGER"
|
32
32
|
end
|
33
33
|
|
34
|
-
assert_equal "OVERRIDDEN LOGGER",
|
34
|
+
assert_equal "OVERRIDDEN LOGGER", ErrornotNotifier.logger
|
35
35
|
end
|
36
36
|
end
|
data/test/sender_test.rb
CHANGED
@@ -7,15 +7,16 @@ class SenderTest < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def build_sender(opts = {})
|
10
|
-
config =
|
10
|
+
config = ErrornotNotifier::Configuration.new
|
11
|
+
config.host = 'localhost'
|
11
12
|
opts.each {|opt, value| config.send(:"#{opt}=", value) }
|
12
|
-
|
13
|
+
ErrornotNotifier::Sender.new(config)
|
13
14
|
end
|
14
15
|
|
15
16
|
def send_exception(args = {})
|
16
17
|
notice = args.delete(:notice) || build_notice_data
|
17
18
|
sender = args.delete(:sender) || build_sender(args)
|
18
|
-
sender.
|
19
|
+
sender.send_to_errornot(notice)
|
19
20
|
sender
|
20
21
|
end
|
21
22
|
|
@@ -29,7 +30,7 @@ class SenderTest < Test::Unit::TestCase
|
|
29
30
|
http
|
30
31
|
end
|
31
32
|
|
32
|
-
should "post to
|
33
|
+
should "post to Errornot when using an HTTP proxy" do
|
33
34
|
response = stub(:body => 'body')
|
34
35
|
http = stub(:post => response,
|
35
36
|
:read_timeout= => nil,
|
@@ -38,7 +39,7 @@ class SenderTest < Test::Unit::TestCase
|
|
38
39
|
proxy = stub(:new => http)
|
39
40
|
Net::HTTP.stubs(:Proxy => proxy)
|
40
41
|
|
41
|
-
url = "http://hoptoadapp.com:80#{
|
42
|
+
url = "http://hoptoadapp.com:80#{ErrornotNotifier::Sender::NOTICES_URI}"
|
42
43
|
uri = URI.parse(url)
|
43
44
|
|
44
45
|
proxy_host = 'some.host'
|
@@ -50,8 +51,8 @@ class SenderTest < Test::Unit::TestCase
|
|
50
51
|
:proxy_port => proxy_port,
|
51
52
|
:proxy_user => proxy_user,
|
52
53
|
:proxy_pass => proxy_pass)
|
53
|
-
assert_received(http, :post) do |expect|
|
54
|
-
expect.with(uri.path, anything,
|
54
|
+
assert_received(http, :post) do |expect|
|
55
|
+
expect.with(uri.path, anything, ErrornotNotifier::HEADERS)
|
55
56
|
end
|
56
57
|
assert_received(Net::HTTP, :Proxy) do |expect|
|
57
58
|
expect.with(proxy_host, proxy_port, proxy_user, proxy_pass)
|
@@ -60,16 +61,16 @@ class SenderTest < Test::Unit::TestCase
|
|
60
61
|
|
61
62
|
should "post to the right url for non-ssl" do
|
62
63
|
http = stub_http
|
63
|
-
url = "http://hoptoadapp.com:80#{
|
64
|
+
url = "http://hoptoadapp.com:80#{ErrornotNotifier::Sender::NOTICES_URI}"
|
64
65
|
uri = URI.parse(url)
|
65
66
|
send_exception(:secure => false)
|
66
|
-
assert_received(http, :post) {|expect| expect.with(uri.path, anything,
|
67
|
+
assert_received(http, :post) {|expect| expect.with(uri.path, anything, ErrornotNotifier::HEADERS) }
|
67
68
|
end
|
68
69
|
|
69
70
|
should "post to the right path for ssl" do
|
70
71
|
http = stub_http
|
71
72
|
send_exception(:secure => true)
|
72
|
-
assert_received(http, :post) {|expect| expect.with(
|
73
|
+
assert_received(http, :post) {|expect| expect.with(ErrornotNotifier::Sender::NOTICES_URI, anything, ErrornotNotifier::HEADERS) }
|
73
74
|
end
|
74
75
|
|
75
76
|
should "default the open timeout to 2 seconds" do
|
@@ -99,13 +100,13 @@ class SenderTest < Test::Unit::TestCase
|
|
99
100
|
should "connect to the right port for ssl" do
|
100
101
|
stub_http
|
101
102
|
send_exception(:secure => true)
|
102
|
-
assert_received(Net::HTTP, :new) {|expect| expect.with("
|
103
|
+
assert_received(Net::HTTP, :new) {|expect| expect.with("localhost", 443) }
|
103
104
|
end
|
104
105
|
|
105
106
|
should "connect to the right port for non-ssl" do
|
106
107
|
stub_http
|
107
108
|
send_exception(:secure => false)
|
108
|
-
assert_received(Net::HTTP, :new) {|expect| expect.with("
|
109
|
+
assert_received(Net::HTTP, :new) {|expect| expect.with("localhost", 80) }
|
109
110
|
end
|
110
111
|
|
111
112
|
should "use ssl if secure" do
|