exception_notification 4.1.4 → 4.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,11 +3,5 @@ require File.expand_path('../../config/environment', __FILE__)
3
3
  require 'rails/test_help'
4
4
 
5
5
  class ActiveSupport::TestCase
6
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7
- #
8
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
- # -- they do not yet inherit this setting
10
- fixtures :all
11
-
12
6
  # Add more helper methods to be used by all tests here...
13
7
  end
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'action_mailer'
2
3
 
3
4
  class EmailNotifierTest < ActiveSupport::TestCase
4
5
  setup do
@@ -100,15 +101,7 @@ class EmailNotifierTest < ActiveSupport::TestCase
100
101
  end
101
102
 
102
103
  test "mail should have a descriptive subject" do
103
- # On Rails < 4.1 the subject prefix has two spaces before the rest of the
104
- # subject content.
105
- if Gem::Version.new(ActionMailer::VERSION::STRING) < Gem::Version.new('4.1')
106
- prefix = '[Dummy ERROR] '
107
- else
108
- # On Rails 4.1 the subject prefix has a single space.
109
- prefix = '[Dummy ERROR] '
110
- end
111
- assert_equal @mail.subject, prefix + '(ZeroDivisionError) "divided by 0"'
104
+ assert_match /^\[Dummy ERROR\]\s+\(ZeroDivisionError\) "divided by 0"$/, @mail.subject
112
105
  end
113
106
 
114
107
  test "mail should say exception was raised in background at show timestamp" do
@@ -127,7 +120,7 @@ class EmailNotifierTest < ActiveSupport::TestCase
127
120
  end
128
121
 
129
122
  test "mail should contain backtrace in body" do
130
- assert @mail.encoded.include?("test/exception_notifier/email_notifier_test.rb:8"), "\n#{@mail.inspect}"
123
+ assert @mail.encoded.include?("test/exception_notifier/email_notifier_test.rb:9"), "\n#{@mail.inspect}"
131
124
  end
132
125
 
133
126
  test "mail should contain data in body" do
@@ -147,12 +140,12 @@ class EmailNotifierTest < ActiveSupport::TestCase
147
140
  rescue => e
148
141
  @ignored_exception = e
149
142
  unless ExceptionNotifier.ignored_exceptions.include?(@ignored_exception.class.name)
150
- @ignored_mail = @email_notifier.create_email(@ignored_exception)
143
+ ignored_mail = @email_notifier.create_email(@ignored_exception)
151
144
  end
152
145
  end
153
146
 
154
147
  assert_equal @ignored_exception.class.inspect, "ActiveRecord::RecordNotFound"
155
- assert_nil @ignored_mail
148
+ assert_nil ignored_mail
156
149
  end
157
150
 
158
151
  test "should encode environment strings" do
@@ -175,21 +168,54 @@ class EmailNotifierTest < ActiveSupport::TestCase
175
168
  assert_match /invalid_encoding\s+: R__sum__/, mail.encoded
176
169
  end
177
170
 
178
- if defined?(Rails) && ('4.2'...'5.0').cover?(Rails.version)
179
- test "should be able to specify ActionMailer::MessageDelivery method" do
180
- email_notifier = ExceptionNotifier::EmailNotifier.new(
181
- :email_prefix => '[Dummy ERROR] ',
182
- :sender_address => %{"Dummy Notifier" <dummynotifier@example.com>},
183
- :exception_recipients => %w{dummyexceptions@example.com},
184
- :deliver_with => :deliver_now
185
- )
186
- # In Rails 4.2, it gives deprecation warning like "`#deliver` is
187
- # deprecated and will be removed in Rails 5." when "#deliver" is
188
- # used. If methods like "#deliver_now" is used, it should not
189
- # give any warnings.
190
- assert_silent do
191
- email_notifier.call(@exception)
192
- end
171
+ test "should send email using ActionMailer" do
172
+ ActionMailer::Base.deliveries.clear
173
+
174
+ email_notifier = ExceptionNotifier::EmailNotifier.new(
175
+ :email_prefix => '[Dummy ERROR] ',
176
+ :sender_address => %{"Dummy Notifier" <dummynotifier@example.com>},
177
+ :exception_recipients => %w{dummyexceptions@example.com},
178
+ :delivery_method => :test
179
+ )
180
+
181
+ email_notifier.call(@exception)
182
+
183
+ assert_equal 1, ActionMailer::Base.deliveries.count
184
+ end
185
+
186
+ test "should be able to specify ActionMailer::MessageDelivery method" do
187
+ ActionMailer::Base.deliveries.clear
188
+
189
+ if ActionMailer.version < Gem::Version.new("4.2")
190
+ deliver_with = :deliver
191
+ else
192
+ deliver_with = :deliver_now
193
193
  end
194
+
195
+ email_notifier = ExceptionNotifier::EmailNotifier.new(
196
+ :email_prefix => '[Dummy ERROR] ',
197
+ :sender_address => %{"Dummy Notifier" <dummynotifier@example.com>},
198
+ :exception_recipients => %w{dummyexceptions@example.com},
199
+ :deliver_with => deliver_with
200
+ )
201
+
202
+ email_notifier.call(@exception)
203
+
204
+ assert_equal 1, ActionMailer::Base.deliveries.count
205
+ end
206
+
207
+ test "should lazily evaluate exception_recipients" do
208
+ exception_recipients = %w{first@example.com second@example.com}
209
+ email_notifier = ExceptionNotifier::EmailNotifier.new(
210
+ :email_prefix => '[Dummy ERROR] ',
211
+ :sender_address => %{"Dummy Notifier" <dummynotifier@example.com>},
212
+ :exception_recipients => -> { [ exception_recipients.shift ] },
213
+ :delivery_method => :test
214
+ )
215
+
216
+ mail = email_notifier.call(@exception)
217
+ assert_equal %w{first@example.com}, mail.to
218
+ mail = email_notifier.call(@exception)
219
+ assert_equal %w{second@example.com}, mail.to
194
220
  end
195
221
  end
@@ -0,0 +1,88 @@
1
+ require 'test_helper'
2
+ require 'httparty'
3
+
4
+ class MattermostNotifierTest < ActiveSupport::TestCase
5
+
6
+ test "should send notification if properly configured" do
7
+ options = {
8
+ :webhook_url => 'http://localhost:8000'
9
+ }
10
+ mattermost_notifier = ExceptionNotifier::MattermostNotifier.new
11
+ mattermost_notifier.httparty = FakeHTTParty.new
12
+
13
+ options = mattermost_notifier.call ArgumentError.new("foo"), options
14
+
15
+ body = ActiveSupport::JSON.decode options[:body]
16
+ assert body.has_key? 'text'
17
+ assert body.has_key? 'username'
18
+
19
+ text = body['text'].split("\n")
20
+ assert_equal 4, text.size
21
+ assert_equal '@channel', text[0]
22
+ assert_equal 'An *ArgumentError* occured.', text[2]
23
+ assert_equal '*foo*', text[3]
24
+ end
25
+
26
+ test "should send notification with create issue link if specified" do
27
+ options = {
28
+ :webhook_url => 'http://localhost:8000',
29
+ :git_url => 'github.com/aschen'
30
+ }
31
+ mattermost_notifier = ExceptionNotifier::MattermostNotifier.new
32
+ mattermost_notifier.httparty = FakeHTTParty.new
33
+
34
+ options = mattermost_notifier.call ArgumentError.new("foo"), options
35
+
36
+ body = ActiveSupport::JSON.decode options[:body]
37
+
38
+ text = body['text'].split("\n")
39
+ assert_equal 5, text.size
40
+ assert_equal '[Create an issue](github.com/aschen/dummy/issues/new/?issue%5Btitle%5D=%5BBUG%5D+Error+500+%3A++%28ArgumentError%29+foo)', text[4]
41
+ end
42
+
43
+ test 'should add username and icon_url params to the notification if specified' do
44
+ options = {
45
+ :webhook_url => 'http://localhost:8000',
46
+ :username => "Test Bot",
47
+ :avatar => 'http://site.com/icon.png'
48
+ }
49
+ mattermost_notifier = ExceptionNotifier::MattermostNotifier.new
50
+ mattermost_notifier.httparty = FakeHTTParty.new
51
+
52
+ options = mattermost_notifier.call ArgumentError.new("foo"), options
53
+
54
+ body = ActiveSupport::JSON.decode options[:body]
55
+
56
+ assert_equal 'Test Bot', body['username']
57
+ assert_equal 'http://site.com/icon.png', body['icon_url']
58
+ end
59
+
60
+ test 'should add other HTTParty options to params' do
61
+ options = {
62
+ :webhook_url => 'http://localhost:8000',
63
+ :username => "Test Bot",
64
+ :avatar => 'http://site.com/icon.png',
65
+ :basic_auth => {
66
+ :username => 'clara',
67
+ :password => 'password'
68
+ }
69
+ }
70
+ mattermost_notifier = ExceptionNotifier::MattermostNotifier.new
71
+ mattermost_notifier.httparty = FakeHTTParty.new
72
+
73
+ options = mattermost_notifier.call ArgumentError.new("foo"), options
74
+
75
+ assert options.has_key? :basic_auth
76
+ assert 'clara', options[:basic_auth][:username]
77
+ assert 'password', options[:basic_auth][:password]
78
+ end
79
+
80
+ end
81
+
82
+ class FakeHTTParty
83
+
84
+ def post(url, options)
85
+ return options
86
+ end
87
+
88
+ end
@@ -5,8 +5,9 @@ class SlackNotifierTest < ActiveSupport::TestCase
5
5
 
6
6
  def setup
7
7
  @exception = fake_exception
8
- @exception.stubs(:backtrace).returns(["backtrace line 1", "backtrace line 2"])
8
+ @exception.stubs(:backtrace).returns(fake_backtrace)
9
9
  @exception.stubs(:message).returns('exception message')
10
+ Socket.stubs(:gethostname).returns('example.com')
10
11
  end
11
12
 
12
13
  test "should send a slack notification if properly configured" do
@@ -130,7 +131,7 @@ class SlackNotifierTest < ActiveSupport::TestCase
130
131
  Slack::Notifier.any_instance.expects(:ping).with('',
131
132
  {:icon_url => 'icon',
132
133
  :attachments => [
133
- {:text => "backtrace line 1\nbacktrace line 2",
134
+ {:text => fake_backtrace.join("\n"),
134
135
  :color => 'danger'}
135
136
  ]})
136
137
 
@@ -153,11 +154,23 @@ class SlackNotifierTest < ActiveSupport::TestCase
153
154
  StandardError.new('my custom error')
154
155
  end
155
156
 
156
- def fake_notification(exception=@exception, data_string=nil)
157
+ def fake_backtrace
158
+ [
159
+ "backtrace line 1",
160
+ "backtrace line 2",
161
+ "backtrace line 3",
162
+ "backtrace line 4",
163
+ "backtrace line 5",
164
+ "backtrace line 6",
165
+ ]
166
+ end
167
+
168
+ def fake_notification(exception = @exception, data_string = nil)
157
169
  text = "*An exception occurred while doing*: ` <>`\n"
158
170
 
159
171
  fields = [ { title: 'Exception', value: exception.message} ]
160
- fields.push({ title: 'Backtrace', value: "```backtrace line 1\nbacktrace line 2```" }) if exception.backtrace
172
+ fields.push({ title: 'Hostname', value: 'example.com' })
173
+ fields.push({ title: 'Backtrace', value: "```#{fake_backtrace.join("\n")}```" }) if exception.backtrace
161
174
  fields.push({ title: 'Data', value: "```#{data_string}```" }) if data_string
162
175
 
163
176
  { attachments: [ color: 'danger', text: text, fields: fields, mrkdwn_in: %w(text fields) ] }
@@ -2,7 +2,9 @@ require 'test_helper'
2
2
 
3
3
  class ExceptionNotifierTest < ActiveSupport::TestCase
4
4
  test "should have default ignored exceptions" do
5
- assert_equal ExceptionNotifier.ignored_exceptions, ['ActiveRecord::RecordNotFound', 'AbstractController::ActionNotFound', 'ActionController::RoutingError', 'ActionController::UnknownFormat']
5
+ assert_equal ExceptionNotifier.ignored_exceptions,
6
+ ['ActiveRecord::RecordNotFound', 'AbstractController::ActionNotFound', 'ActionController::RoutingError',
7
+ 'ActionController::UnknownFormat', 'ActionController::UrlGenerationError']
6
8
  end
7
9
 
8
10
  test "should have email notifier registered" do
@@ -24,6 +26,7 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
24
26
  assert_equal ExceptionNotifier.notifiers.sort, [:email, :proc]
25
27
 
26
28
  exception = StandardError.new
29
+
27
30
  ExceptionNotifier.notify_exception(exception)
28
31
  assert called
29
32
 
@@ -15,4 +15,4 @@ require File.expand_path("../dummy/test/test_helper.rb", __FILE__)
15
15
  require "mocha/setup"
16
16
 
17
17
  Rails.backtrace_cleaner.remove_silencers!
18
-
18
+ ExceptionNotifier.testing_mode!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.4
4
+ version: 4.2.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamis Buck
@@ -9,50 +9,68 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-07 00:00:00.000000000 Z
12
+ date: 2016-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '4.0'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '6'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: '4.0'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '6'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: activesupport
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
32
- - - "~>"
38
+ - - ">="
33
39
  - !ruby/object:Gem::Version
34
40
  version: '4.0'
41
+ - - "<"
42
+ - !ruby/object:Gem::Version
43
+ version: '6'
35
44
  type: :runtime
36
45
  prerelease: false
37
46
  version_requirements: !ruby/object:Gem::Requirement
38
47
  requirements:
39
- - - "~>"
48
+ - - ">="
40
49
  - !ruby/object:Gem::Version
41
50
  version: '4.0'
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: '6'
42
54
  - !ruby/object:Gem::Dependency
43
55
  name: rails
44
56
  requirement: !ruby/object:Gem::Requirement
45
57
  requirements:
46
- - - "~>"
58
+ - - ">="
47
59
  - !ruby/object:Gem::Version
48
60
  version: '4.0'
61
+ - - "<"
62
+ - !ruby/object:Gem::Version
63
+ version: '6'
49
64
  type: :development
50
65
  prerelease: false
51
66
  version_requirements: !ruby/object:Gem::Requirement
52
67
  requirements:
53
- - - "~>"
68
+ - - ">="
54
69
  - !ruby/object:Gem::Version
55
70
  version: '4.0'
71
+ - - "<"
72
+ - !ruby/object:Gem::Version
73
+ version: '6'
56
74
  - !ruby/object:Gem::Dependency
57
75
  name: resque
58
76
  requirement: !ruby/object:Gem::Requirement
@@ -163,14 +181,14 @@ dependencies:
163
181
  requirements:
164
182
  - - "~>"
165
183
  - !ruby/object:Gem::Version
166
- version: 1.0.0
184
+ version: 2.0.0
167
185
  type: :development
168
186
  prerelease: false
169
187
  version_requirements: !ruby/object:Gem::Requirement
170
188
  requirements:
171
189
  - - "~>"
172
190
  - !ruby/object:Gem::Version
173
- version: 1.0.0
191
+ version: 2.0.0
174
192
  - !ruby/object:Gem::Dependency
175
193
  name: hipchat
176
194
  requirement: !ruby/object:Gem::Requirement
@@ -221,6 +239,7 @@ extra_rdoc_files: []
221
239
  files:
222
240
  - Appraisals
223
241
  - CHANGELOG.rdoc
242
+ - CODE_OF_CONDUCT.md
224
243
  - CONTRIBUTING.md
225
244
  - Gemfile
226
245
  - MIT-LICENSE
@@ -236,6 +255,7 @@ files:
236
255
  - gemfiles/rails4_0.gemfile
237
256
  - gemfiles/rails4_1.gemfile
238
257
  - gemfiles/rails4_2.gemfile
258
+ - gemfiles/rails5_0.gemfile
239
259
  - lib/exception_notification.rb
240
260
  - lib/exception_notification/rack.rb
241
261
  - lib/exception_notification/rails.rb
@@ -247,6 +267,7 @@ files:
247
267
  - lib/exception_notifier/email_notifier.rb
248
268
  - lib/exception_notifier/hipchat_notifier.rb
249
269
  - lib/exception_notifier/irc_notifier.rb
270
+ - lib/exception_notifier/mattermost_notifier.rb
250
271
  - lib/exception_notifier/modules/backtrace_cleaner.rb
251
272
  - lib/exception_notifier/notifier.rb
252
273
  - lib/exception_notifier/slack_notifier.rb
@@ -270,8 +291,6 @@ files:
270
291
  - lib/generators/exception_notification/install_generator.rb
271
292
  - lib/generators/exception_notification/templates/exception_notification.rb
272
293
  - test/dummy/.gitignore
273
- - test/dummy/Gemfile
274
- - test/dummy/Gemfile.lock
275
294
  - test/dummy/Rakefile
276
295
  - test/dummy/app/controllers/application_controller.rb
277
296
  - test/dummy/app/controllers/posts_controller.rb
@@ -321,7 +340,6 @@ files:
321
340
  - test/dummy/public/stylesheets/.gitkeep
322
341
  - test/dummy/public/stylesheets/scaffold.css
323
342
  - test/dummy/script/rails
324
- - test/dummy/test/fixtures/posts.yml
325
343
  - test/dummy/test/functional/posts_controller_test.rb
326
344
  - test/dummy/test/test_helper.rb
327
345
  - test/exception_notification/rack_test.rb
@@ -329,12 +347,13 @@ files:
329
347
  - test/exception_notifier/email_notifier_test.rb
330
348
  - test/exception_notifier/hipchat_notifier_test.rb
331
349
  - test/exception_notifier/irc_notifier_test.rb
350
+ - test/exception_notifier/mattermost_notifier_test.rb
332
351
  - test/exception_notifier/sidekiq_test.rb
333
352
  - test/exception_notifier/slack_notifier_test.rb
334
353
  - test/exception_notifier/webhook_notifier_test.rb
335
354
  - test/exception_notifier_test.rb
336
355
  - test/test_helper.rb
337
- homepage: http://smartinez87.github.com/exception_notification
356
+ homepage: https://smartinez87.github.io/exception_notification/
338
357
  licenses:
339
358
  - MIT
340
359
  metadata: {}
@@ -354,14 +373,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
354
373
  version: 1.8.11
355
374
  requirements: []
356
375
  rubyforge_project:
357
- rubygems_version: 2.4.5.1
376
+ rubygems_version: 2.5.1
358
377
  signing_key:
359
378
  specification_version: 4
360
379
  summary: Exception notification for Rails apps
361
380
  test_files:
362
381
  - test/dummy/.gitignore
363
- - test/dummy/Gemfile
364
- - test/dummy/Gemfile.lock
365
382
  - test/dummy/Rakefile
366
383
  - test/dummy/app/controllers/application_controller.rb
367
384
  - test/dummy/app/controllers/posts_controller.rb
@@ -411,7 +428,6 @@ test_files:
411
428
  - test/dummy/public/stylesheets/.gitkeep
412
429
  - test/dummy/public/stylesheets/scaffold.css
413
430
  - test/dummy/script/rails
414
- - test/dummy/test/fixtures/posts.yml
415
431
  - test/dummy/test/functional/posts_controller_test.rb
416
432
  - test/dummy/test/test_helper.rb
417
433
  - test/exception_notification/rack_test.rb
@@ -419,6 +435,7 @@ test_files:
419
435
  - test/exception_notifier/email_notifier_test.rb
420
436
  - test/exception_notifier/hipchat_notifier_test.rb
421
437
  - test/exception_notifier/irc_notifier_test.rb
438
+ - test/exception_notifier/mattermost_notifier_test.rb
422
439
  - test/exception_notifier/sidekiq_test.rb
423
440
  - test/exception_notifier/slack_notifier_test.rb
424
441
  - test/exception_notifier/webhook_notifier_test.rb