exception_notification-rake 0.0.1.alpha1 → 0.0.1.alpha2

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.
@@ -13,8 +13,9 @@ Gem::Specification.new do |s|
13
13
  ' sending mail upon failures in Rake tasks'
14
14
 
15
15
  s.add_runtime_dependency 'exception_notification', '~> 3.0.0'
16
- # TODO how to specify rake dependency?
17
- s.add_development_dependency 'rake'
16
+ # NB: Rake before 0.9.0 won't support the exception hook we're using
17
+ s.add_runtime_dependency 'rake', '>= 0.9.0'
18
+ s.add_development_dependency 'rails', '~> 3.2.0'
18
19
 
19
20
  s.files = `git ls-files`.split("\n")
20
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -0,0 +1,21 @@
1
+ require 'delegate'
2
+
3
+ class ExceptionNotifier
4
+ class Rake
5
+ class MultiDelegator
6
+
7
+ def initialize(delegates)
8
+ @delegates = delegates.map do |del|
9
+ SimpleDelegator.new(del)
10
+ end
11
+ end
12
+
13
+ def method_missing(m, *args, &block)
14
+ return_values = @delegates.map do |del|
15
+ del.method_missing(m, *args, &block)
16
+ end
17
+ return_values.first
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,9 +1,11 @@
1
1
  require 'exception_notifier'
2
2
 
3
3
  class ExceptionNotifier
4
- class Rake
5
4
 
6
- ALWAYS_TRUE = lambda { true }
5
+ # Append application view path to the ExceptionNotifier lookup context.
6
+ Notifier.append_view_path "#{File.dirname(__FILE__)}/views"
7
+
8
+ class Rake
7
9
 
8
10
  @notifier_options = {}
9
11
 
@@ -11,8 +13,7 @@ class ExceptionNotifier
11
13
  !@notifier_options.empty?
12
14
  end
13
15
 
14
- def self.configure(config, options = {})
15
- # TODO add ExceptionNotifier to middleware if needed
16
+ def self.configure(options = {})
16
17
  @notifier_options.merge!(default_notifier_options)
17
18
  @notifier_options.merge!(options)
18
19
  end
@@ -20,10 +21,7 @@ class ExceptionNotifier
20
21
  def self.default_notifier_options
21
22
  {
22
23
  :email_prefix => "[Rake Failure] ",
23
- # TODO add stdin/stderr sections with captured output
24
- :background_sections => %w(backtrace),
25
- # TODO include this only if ExceptionNotifer not already in use
26
- :ignore_if => ALWAYS_TRUE,
24
+ :background_sections => %w(rake backtrace),
27
25
  }
28
26
  end
29
27
 
@@ -31,11 +29,15 @@ class ExceptionNotifier
31
29
  @notifier_options
32
30
  end
33
31
 
34
- def self.maybe_deliver_notification(exception)
35
- # TODO needs test
32
+ def self.maybe_deliver_notification(exception, data={})
36
33
  if configured?
34
+ options = notifier_options
35
+ if !data.empty?
36
+ options = options.dup
37
+ options[:data] = data.merge(options[:data] || {})
38
+ end
37
39
  ExceptionNotifier::Notifier.background_exception_notification(
38
- exception, notifier_options).deliver
40
+ exception, options).deliver
39
41
  end
40
42
  end
41
43
 
@@ -10,8 +10,13 @@ class ExceptionNotifier
10
10
  end
11
11
 
12
12
  def display_error_message_with_notifications(ex)
13
- ExceptionNotifier::Rake.maybe_deliver_notification(ex)
14
13
  display_error_message_without_notifications(ex)
14
+ ExceptionNotifier::Rake.maybe_deliver_notification(ex,
15
+ :rake_command_line => reconstruct_command_line)
16
+ end
17
+
18
+ def reconstruct_command_line
19
+ "rake #{ARGV.join(' ')}"
15
20
  end
16
21
  end
17
22
  end
@@ -1,5 +1,5 @@
1
1
  class ExceptionNotifier
2
2
  class Rake
3
- VERSION = '0.0.1.alpha1'
3
+ VERSION = '0.0.1.alpha2'
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ <%= raw @data[:rake_command_line] %>
@@ -0,0 +1 @@
1
+ <%= raw @data[:rake_command_line] %>
@@ -0,0 +1,34 @@
1
+ require 'test/unit'
2
+
3
+ require 'exception_notifier/rake/multi_delegator'
4
+
5
+ class MultiDelegatorTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @delegate1 = []
9
+ @delegate2 = [42]
10
+ end
11
+
12
+ def test_one_delegate
13
+ delegator = ExceptionNotifier::Rake::MultiDelegator.new([@delegate1])
14
+ result = delegator.push(42)
15
+ assert_equal [42], @delegate1
16
+ assert_equal [42], result
17
+ end
18
+
19
+ def test_multiple_delegates
20
+ delegator = ExceptionNotifier::Rake::MultiDelegator.new([@delegate1, @delegate2])
21
+ result = delegator.push(43)
22
+ assert_equal [43], result
23
+ assert_equal [43], @delegate1
24
+ assert_equal [42, 43], @delegate2
25
+ end
26
+
27
+ def test_multiple_delegates_block_argument
28
+ delegator = ExceptionNotifier::Rake::MultiDelegator.new([@delegate1, @delegate2])
29
+ result = delegator.map! do |e| e + 1 end
30
+ assert_equal [], result
31
+ assert_equal [], @delegate1
32
+ assert_equal [43], @delegate2
33
+ end
34
+ end
data/test/rake_test.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'test/unit'
2
+ require 'mocha/setup'
3
+
2
4
  require 'exception_notifier/rake'
3
5
 
4
6
  class RakeTest < Test::Unit::TestCase
@@ -8,8 +10,15 @@ class RakeTest < Test::Unit::TestCase
8
10
  assert !ExceptionNotifier::Rake.configured?
9
11
  end
10
12
 
13
+ def expect_delivery(exception, options)
14
+ mail = Object.new
15
+ ExceptionNotifier::Notifier.expects(:background_exception_notification)
16
+ .with(exception, options).returns(mail)
17
+ mail.expects(:deliver)
18
+ end
19
+
11
20
  def test_configure_only_default_options
12
- ExceptionNotifier::Rake.configure({})
21
+ ExceptionNotifier::Rake.configure
13
22
  assert ExceptionNotifier::Rake.configured?
14
23
  assert_equal ExceptionNotifier::Rake.default_notifier_options,
15
24
  ExceptionNotifier::Rake.notifier_options
@@ -20,9 +29,31 @@ class RakeTest < Test::Unit::TestCase
20
29
  :sender_address => 'foo@example.com',
21
30
  :exception_recipients => ['bar@example.com'],
22
31
  }
23
- ExceptionNotifier::Rake.configure({}, some_options)
32
+ ExceptionNotifier::Rake.configure some_options
24
33
  assert ExceptionNotifier::Rake.configured?
25
34
  assert_equal some_options.merge(ExceptionNotifier::Rake.default_notifier_options),
26
35
  ExceptionNotifier::Rake.notifier_options
27
36
  end
37
+
38
+ def test_maybe_deliver_notifications_without_configuration
39
+ ExceptionNotifier::Rake.maybe_deliver_notification(Exception.new)
40
+ end
41
+
42
+ def test_maybe_deliver_notifications_with_config
43
+ ExceptionNotifier::Rake.configure
44
+ ex = Exception.new
45
+ expect_delivery(ex, ExceptionNotifier::Rake.notifier_options)
46
+ ExceptionNotifier::Rake.maybe_deliver_notification(ex)
47
+ end
48
+
49
+ def test_maybe_deliver_notifications_with_data
50
+ ExceptionNotifier::Rake.configure
51
+ data = {:foo => :bar}
52
+ options = ExceptionNotifier::Rake.notifier_options
53
+ original_options = options.dup
54
+ ex = Exception.new
55
+ expect_delivery(ex, options.merge({:data => data}))
56
+ ExceptionNotifier::Rake.maybe_deliver_notification(ex, data)
57
+ assert_equal(original_options, options)
58
+ end
28
59
  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.0.1.alpha1
4
+ version: 0.0.1.alpha2
5
5
  prerelease: 6
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: 2013-01-30 00:00:00.000000000 Z
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: exception_notification
@@ -34,15 +34,31 @@ dependencies:
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
37
+ version: 0.9.0
38
+ type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: 0.9.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 3.2.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
46
62
  description: An extension of the exception_notification gem to support sending mail
47
63
  upon failures in Rake tasks
48
64
  email:
@@ -58,9 +74,13 @@ files:
58
74
  - Rakefile
59
75
  - exception_notification-rake.gemspec
60
76
  - lib/exception_notifier/rake.rb
77
+ - lib/exception_notifier/rake/multi_delegator.rb
61
78
  - lib/exception_notifier/rake/rake.rb
62
79
  - lib/exception_notifier/rake/rake_patch.rb
63
80
  - lib/exception_notifier/rake/version.rb
81
+ - lib/exception_notifier/rake/views/exception_notifier/_rake.html.erb
82
+ - lib/exception_notifier/rake/views/exception_notifier/_rake.text.erb
83
+ - test/multi_delegator_test.rb
64
84
  - test/rake_test.rb
65
85
  homepage: https://github.com/nikhaldi/exception_notification-rake
66
86
  licenses: []
@@ -87,5 +107,6 @@ signing_key:
87
107
  specification_version: 3
88
108
  summary: Sending exception notifications upon Rake task failures
89
109
  test_files:
110
+ - test/multi_delegator_test.rb
90
111
  - test/rake_test.rb
91
112
  has_rdoc: