exception_no 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODJlYTU1M2UyY2RmZjJjMzgyN2E1ZjIwMjcyYmNjNGZmMTFiYzhjMQ==
4
+ OGYwNDYzMDA0NmQzN2U4YTU2MGYxMzQ3OTQ5YTY5NTQ5Y2JiNTExNA==
5
5
  data.tar.gz: !binary |-
6
- NDc5Y2Y2OWI1OWI0YmQ3YTE5YTEzZTgzMGExNTM2M2RlMGYwMDY5NA==
6
+ NWY4ODFiOGIwNDI3YzcwZjBkOGE3YjE0ZGY4NTQ3MzEzNDM5ZDM2OQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OGNiMTBlNmU3OTFiYjM5Mjg5OTQ5ZDMyNzczZWM4MjhmMGFiNTljNzQzMzgz
10
- YzA2OGQwY2Y0ZDUzMTIxNTQzYzgxZjhkN2YyOGQyMDNiNzNkN2Y0YTZlYWQy
11
- MDBkNzJjZDE1MjA4ZDJhMTYwMTE4ODExZDA4YjE5NjliMzdhMzU=
9
+ N2Q3NWE4ZGEyZDI4NTg4MTA5Y2ZkMTQ0MmU4MWQyODUxMzAyMzYwZTk3ZjFm
10
+ NjBhZTFmZTcxMTg4M2JjN2NlZjEwNzAyZGNiNTQyMGI4MmNhNzEzMzBiMDQ4
11
+ YzRlYjI1ZGVkNzBkMzM0MTUzYzFkY2I3YzZhYjk4NjRhMDFkMDc=
12
12
  data.tar.gz: !binary |-
13
- NTdhNTUwYmZmNDg1ZTFlZTVlMmFkZGNiZDEyYzM2MWIwZmRhY2Y0Y2YyOWFk
14
- NGY2MTYwNmFjNTFkMDk0NTdjYTQ3NzQ0MmEzYzc4YjczZDc2MzgyNzYwY2Iw
15
- MjlmMDZmZjI5ZmE5MjRkZWU3N2NiZTQyOTEzNzQwMDE3NTlmOTU=
13
+ MWI4YWI5MzQwNTU3ZjNiYzZjYmU1ZDBhNjUwNDkxYmIwMTI3OGMzNDJiYTgz
14
+ Y2Y3ZDk5OGQzYTU3OTViNmNiMTc2MGUyODBjY2MxYzFjOTNmNTMyY2UwYzhl
15
+ ZjBlYjJkMGM2MmFjMmQ0MmNhMDQ5NWFhOTZkMGMxNjU0MWEyZDk=
data/lib/exception_no.rb CHANGED
@@ -2,20 +2,20 @@ require "net/smtp"
2
2
  require "erb"
3
3
 
4
4
  class ExceptionNo
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.4"
6
6
 
7
7
  attr_accessor :backtrace_filter
8
- attr_accessor :deliver
8
+ attr_accessor :behaviors
9
9
 
10
10
  def initialize(config = {})
11
11
  @config = config
12
12
  @template = ERB.new(TEMPLATE)
13
- @deliver = true
13
+ @behaviors = [:deliver]
14
14
 
15
15
  @backtrace_filter = -> line { true }
16
16
  end
17
17
 
18
- def _notify(exception, options = {})
18
+ def _deliver(exception, options = {})
19
19
  body = @template.result(binding)
20
20
 
21
21
  Net::SMTP.start(@config.fetch(:host), @config.fetch(:port, 25)) do |smtp|
@@ -23,11 +23,9 @@ class ExceptionNo
23
23
  end
24
24
  end
25
25
 
26
- def notify(exception, options = {})
27
- return unless @deliver
28
-
26
+ def deliver(exception, options)
29
27
  begin
30
- _notify(exception, options)
28
+ _deliver(exception, options)
31
29
  rescue => notification_error
32
30
  $stderr.write("*** FAILED SENDING ERROR NOTIFICATION\n")
33
31
  $stderr.write("*** #{notification_error.class}: #{notification_error}\n")
@@ -39,6 +37,11 @@ class ExceptionNo
39
37
  end
40
38
  end
41
39
 
40
+ def notify(exception, options = {})
41
+ deliver(exception, options) if @behaviors.include?(:deliver)
42
+ raise exception if @behaviors.include?(:raise)
43
+ end
44
+
42
45
  TEMPLATE = (<<-'EMAIL').gsub(/^ {2}/, '')
43
46
  From: <%= @config[:from_alias] %> <<%= @config[:from] %>>
44
47
  To: <<%= @config[:to] %>>
data/test/exception_no.rb CHANGED
@@ -10,6 +10,8 @@ setup do
10
10
  end
11
11
 
12
12
  test "deliver exception notification" do |notifier|
13
+ notifier.behaviors = [:deliver]
14
+
13
15
  ex = ArgumentError.new("Really bad argument")
14
16
 
15
17
  notifier.notify(ex)
@@ -26,6 +28,8 @@ test "deliver exception notification" do |notifier|
26
28
  end
27
29
 
28
30
  test "exception messages with multiple lines" do |notifier|
31
+ notifier.behaviors = [:deliver]
32
+
29
33
  notifier.notify(ArgumentError.new("A really\nbad\nargument"))
30
34
 
31
35
  headers, body = parse_email($smtp.outbox.last[:data])
@@ -34,6 +38,8 @@ test "exception messages with multiple lines" do |notifier|
34
38
  end
35
39
 
36
40
  test "includes backtrace information" do |notifier|
41
+ notifier.behaviors = [:deliver]
42
+
37
43
  begin
38
44
  raise ArgumentError, "A bad argument"
39
45
  rescue Exception => ex
@@ -47,6 +53,8 @@ test "includes backtrace information" do |notifier|
47
53
  end
48
54
 
49
55
  test "allows to filter the backtrace" do |notifier|
56
+ notifier.behaviors = [:deliver]
57
+
50
58
  notifier.backtrace_filter = -> line do
51
59
  !line.include?(Gem.path.first)
52
60
  end
@@ -64,12 +72,28 @@ test "allows to filter the backtrace" do |notifier|
64
72
  end
65
73
 
66
74
  test "disable delivery" do |notifier|
67
- notifier.deliver = false
75
+ notifier.behaviors = []
68
76
 
69
77
  notifier.notify(ArgumentError.new)
70
78
 
71
79
  assert_equal $smtp.outbox.size, 0
72
80
  end
73
81
 
82
+ test "raise exception" do |notifier|
83
+ notifier.behaviors = [:raise]
84
+
85
+ assert_raise(ArgumentError) { notifier.notify(ArgumentError.new) }
86
+
87
+ assert_equal $smtp.outbox.size, 0
88
+ end
89
+
90
+ test "raise exception and deliver notification" do |notifier|
91
+ notifier.behaviors = [:raise, :deliver]
92
+
93
+ assert_raise(ArgumentError) { notifier.notify(ArgumentError.new) }
94
+
95
+ assert_equal $smtp.outbox.size, 1
96
+ end
97
+
74
98
  $smtp.stop
75
99
  $smtp.join
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_no
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Educabilia
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-18 00:00:00.000000000 Z
12
+ date: 2014-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mini-smtp-server