exception_notification-rake 0.1.1 → 0.1.2

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.
data/README.md CHANGED
@@ -9,7 +9,7 @@ This Ruby gem is an extension of the [exception_notification gem](http://rubygem
9
9
 
10
10
  If you're using Rails 4 (or you're not using Rails at all), use the latest version of the gem:
11
11
 
12
- gem 'exception_notification-rake', '~> 0.1.1'
12
+ gem 'exception_notification-rake', '~> 0.1.2'
13
13
 
14
14
  If you're using Rails 3, use the 0.0.x line of versions:
15
15
 
@@ -30,7 +30,7 @@ Exception notification must be set up in your Rails config files. In general, yo
30
30
  # Other configuration here, including ActionMailer config ...
31
31
 
32
32
  config.middleware.use ExceptionNotification::Rack,
33
- :ignore_if => lambda { true },
33
+ :ignore_if => lambda { |env, exception| !env[:rake?] }
34
34
  :email => {
35
35
  :sender_address => %{"notifier" <sender.address@example.com>},
36
36
  :exception_recipients => %w{your.email@example.com}
@@ -39,7 +39,7 @@ Exception notification must be set up in your Rails config files. In general, yo
39
39
  ExceptionNotifier::Rake.configure
40
40
  end
41
41
 
42
- **Note:** This uses `:ignore_if` to suppress all exception notifications triggered by the Rails server itself (as opposed to Rake). If you want those notifications as well, omit the `:ignore_if` option.
42
+ **Note:** This uses `:ignore_if` to suppress all exception notifications not triggered by Rake (identified by the `:rake?` property set in the environment of all Rake failures). If you want to see all notifications (i.e., also those triggered by requests to the Rails server), omit the `:ignore_if` option.
43
43
 
44
44
  If you are already using `ExceptionNotifier` anyway, you don't need to configure it again and all you need is:
45
45
 
@@ -69,6 +69,8 @@ If you are already using `ExceptionNotifier` anyway, you don't need to configure
69
69
  ExceptionNotifier::Rake.configure
70
70
  end
71
71
 
72
+ For complete documentation on the Rails 3.2 version see the [corresponding branch on GitHub](https://github.com/nikhaldi/exception_notification-rake/tree/rails3.2).
73
+
72
74
 
73
75
  ### Notification Example
74
76
 
@@ -138,7 +140,7 @@ The most likely options you'll want to use are `:email_prefix` and `:exception_r
138
140
 
139
141
  This will prefix the email subjects of Rake failure notifications with `[Rake Failure]` and will send them to the two given email addresses. Note that if you set the same options when you configure `ExceptionNotifier` mail notifier itself, they will be overridden but for Rake failures only.
140
142
 
141
- `:ignore_if` and `:ignore_exceptions` are also supported.
143
+ `:ignore_if` and `:ignore_exceptions` are also supported. But note that the `:ignore_if` block will be evaluated for all exceptions, not just the ones triggered by Rake (this is unavoidable because of the design of exception_notification). The first argument to the block passed to `:ignore_if` is the environment - for all Rake failures this will be a dictionary with a single `:rake?` key (i.e., `{:rake? => true}`) so that you can distinguish them.
142
144
 
143
145
  If you want to configure sections, which is unlikely, note that by default the sections `['rake', 'backtrace']` are used (where `rake` is a custom section introduced by this gem).
144
146
 
@@ -19,6 +19,16 @@ module ExceptionNotifier
19
19
  @notifier_options.merge!(default_notifier_options)
20
20
  @notifier_options.merge!(options)
21
21
 
22
+ # There is only a single static list registered ignore_ifs. We make
23
+ # ignore_ifs passed to just this configuration only effective for exceptions
24
+ # actually raised through Rake, identified by the :rake? variable in the
25
+ # environment.
26
+ if options[:ignore_if]
27
+ ExceptionNotifier.ignore_if do |exception, passed_options|
28
+ passed_options[:env][:rake?] && options[:ignore_if].call(passed_options[:env], exception)
29
+ end
30
+ end
31
+
22
32
  # Append view path for this gem, assuming that the client is using
23
33
  # ActionMailer::Base. This isn't ideal but there doesn't seem to be
24
34
  # a different way to extend the path.
@@ -29,6 +39,7 @@ module ExceptionNotifier
29
39
  def self.default_notifier_options
30
40
  {
31
41
  :background_sections => %w(rake backtrace),
42
+ :env => {:rake? => true},
32
43
  }
33
44
  end
34
45
 
@@ -53,6 +64,7 @@ module ExceptionNotifier
53
64
 
54
65
  def self.reset_for_test
55
66
  @notifier_options = {}
67
+ ExceptionNotifier.clear_ignore_conditions!
56
68
  end
57
69
  end
58
70
  end
@@ -1,5 +1,5 @@
1
1
  module ExceptionNotifier
2
2
  class Rake
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
data/test/rake_test.rb CHANGED
@@ -6,16 +6,32 @@ require 'exception_notifier/rake'
6
6
 
7
7
  class RakeTest < Test::Unit::TestCase
8
8
 
9
+ class Notifier
10
+ attr_accessor :exception, :options
11
+ def call(exception, options)
12
+ @exception = exception
13
+ @options = options
14
+ end
15
+ end
16
+
9
17
  class IgnoredException < Exception
10
18
  end
11
19
 
12
20
  def setup
13
21
  ExceptionNotifier::Rake.reset_for_test
14
22
  assert !ExceptionNotifier::Rake.configured?
23
+ @notifier = Notifier.new
24
+ ExceptionNotifier.add_notifier 'test_notifier', @notifier
15
25
  end
16
26
 
17
- def expect_delivery(exception, options)
18
- ExceptionNotifier.expects(:notify_exception).with(exception, options)
27
+ def assert_not_notified
28
+ assert_nil @notifier.exception
29
+ assert_nil @notifier.options
30
+ end
31
+
32
+ def assert_notified(exception, options)
33
+ assert_equal exception, @notifier.exception
34
+ assert_equal options, @notifier.options
19
35
  end
20
36
 
21
37
  def test_configure_only_default_options
@@ -38,13 +54,14 @@ class RakeTest < Test::Unit::TestCase
38
54
 
39
55
  def test_maybe_deliver_notifications_without_configuration
40
56
  ExceptionNotifier::Rake.maybe_deliver_notification(Exception.new)
57
+ assert_not_notified
41
58
  end
42
59
 
43
60
  def test_maybe_deliver_notifications_with_config
44
61
  ExceptionNotifier::Rake.configure
45
62
  ex = Exception.new
46
- expect_delivery(ex, ExceptionNotifier::Rake.notifier_options)
47
63
  ExceptionNotifier::Rake.maybe_deliver_notification(ex)
64
+ assert_notified ex, ExceptionNotifier::Rake.notifier_options
48
65
  end
49
66
 
50
67
  def test_maybe_deliver_notifications_with_data
@@ -53,23 +70,34 @@ class RakeTest < Test::Unit::TestCase
53
70
  options = ExceptionNotifier::Rake.notifier_options
54
71
  original_options = options.dup
55
72
  ex = Exception.new
56
- expect_delivery(ex, options.merge({:data => data}))
57
73
  ExceptionNotifier::Rake.maybe_deliver_notification(ex, data)
58
- assert_equal(original_options, options)
74
+ assert_notified ex, options.merge({:data => data})
75
+ assert_equal original_options, options
59
76
  end
60
77
 
61
78
  def test_maybe_deliver_notifications_with_ignore_if
62
79
  ExceptionNotifier::Rake.configure(
63
- ignore_if: lambda { |ex, options| true })
80
+ ignore_if: lambda { |env, exception| true })
64
81
  ExceptionNotifier::Rake.maybe_deliver_notification(Exception.new)
82
+ assert_not_notified
83
+ end
84
+
85
+ def test_maybe_deliver_notifications_with_passing_ignore_if
86
+ ExceptionNotifier::Rake.configure(
87
+ ignore_if: lambda { |env, exception| false })
88
+ ex = Exception.new
89
+ ExceptionNotifier::Rake.maybe_deliver_notification(ex)
90
+ assert_notified ex, ExceptionNotifier::Rake.notifier_options
65
91
  end
66
92
 
67
93
  def test_maybe_deliver_notifications_with_ignore_exceptions
68
94
  ExceptionNotifier::Rake.configure(
69
95
  ignore_exceptions: ['RakeTest::IgnoredException'])
70
96
  ExceptionNotifier::Rake.maybe_deliver_notification(IgnoredException.new)
97
+ assert_not_notified
98
+
71
99
  ex = Exception.new
72
- expect_delivery(ex, ExceptionNotifier::Rake.notifier_options)
73
100
  ExceptionNotifier::Rake.maybe_deliver_notification(ex)
101
+ assert_notified ex, ExceptionNotifier::Rake.notifier_options
74
102
  end
75
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_notification-rake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-18 00:00:00.000000000 Z
12
+ date: 2014-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: exception_notification