exception_handling 2.9.0 → 3.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -3
  3. data/.ruby-version +1 -1
  4. data/Gemfile +16 -11
  5. data/Gemfile.lock +104 -96
  6. data/README.md +3 -7
  7. data/Rakefile +11 -8
  8. data/exception_handling.gemspec +10 -10
  9. data/lib/exception_handling/exception_info.rb +10 -13
  10. data/lib/exception_handling/honeybadger_callbacks.rb +1 -1
  11. data/lib/exception_handling/log_stub_error.rb +1 -2
  12. data/lib/exception_handling/methods.rb +53 -6
  13. data/lib/exception_handling/testing.rb +10 -20
  14. data/lib/exception_handling/version.rb +1 -1
  15. data/lib/exception_handling.rb +13 -42
  16. data/semaphore_ci/setup.sh +3 -0
  17. data/{spec → test}/helpers/controller_helpers.rb +0 -0
  18. data/{spec → test}/helpers/exception_helpers.rb +2 -2
  19. data/{spec/spec_helper.rb → test/test_helper.rb} +42 -63
  20. data/test/unit/exception_handling/exception_catalog_test.rb +85 -0
  21. data/test/unit/exception_handling/exception_description_test.rb +82 -0
  22. data/{spec/unit/exception_handling/exception_info_spec.rb → test/unit/exception_handling/exception_info_test.rb} +114 -153
  23. data/{spec/unit/exception_handling/honeybadger_callbacks_spec.rb → test/unit/exception_handling/honeybadger_callbacks_test.rb} +20 -20
  24. data/{spec/unit/exception_handling/log_error_stub_spec.rb → test/unit/exception_handling/log_error_stub_test.rb} +22 -38
  25. data/{spec/unit/exception_handling/mailer_spec.rb → test/unit/exception_handling/mailer_test.rb} +18 -17
  26. data/test/unit/exception_handling/methods_test.rb +84 -0
  27. data/test/unit/exception_handling/sensu_test.rb +52 -0
  28. data/test/unit/exception_handling_test.rb +1109 -0
  29. metadata +53 -86
  30. data/.jenkins/Jenkinsfile +0 -113
  31. data/.jenkins/ruby_build_pod.yml +0 -18
  32. data/.rspec +0 -3
  33. data/Appraisals +0 -19
  34. data/CHANGELOG.md +0 -77
  35. data/gemfiles/.bundle/config +0 -2
  36. data/gemfiles/rails_4.gemfile +0 -19
  37. data/gemfiles/rails_5.gemfile +0 -19
  38. data/gemfiles/rails_6.gemfile +0 -19
  39. data/lib/exception_handling/escalate_callback.rb +0 -19
  40. data/lib/exception_handling/logging_methods.rb +0 -27
  41. data/spec/rake_test_warning_false.rb +0 -20
  42. data/spec/unit/exception_handling/escalate_callback_spec.rb +0 -81
  43. data/spec/unit/exception_handling/exception_catalog_spec.rb +0 -85
  44. data/spec/unit/exception_handling/exception_description_spec.rb +0 -82
  45. data/spec/unit/exception_handling/logging_methods_spec.rb +0 -38
  46. data/spec/unit/exception_handling/methods_spec.rb +0 -105
  47. data/spec/unit/exception_handling/sensu_spec.rb +0 -51
  48. data/spec/unit/exception_handling_spec.rb +0 -1249
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../spec_helper', __dir__)
3
+ require File.expand_path('../../test_helper', __dir__)
4
4
 
5
5
  module ExceptionHandling
6
- describe HoneybadgerCallbacks do
6
+ class HoneybadgerCallbacksTest < ActiveSupport::TestCase
7
7
 
8
8
  class TestPoroWithAttribute
9
9
  attr_reader :test_attribute
@@ -55,15 +55,15 @@ module ExceptionHandling
55
55
  end
56
56
 
57
57
  context "register_callbacks" do
58
- it "store the callbacks in the honeybadger object" do
58
+ should "store the callbacks in the honeybadger object" do
59
59
  HoneybadgerCallbacks.register_callbacks
60
60
  result = Honeybadger.config.local_variable_filter.call(:variable_name, 'test', [])
61
- expect(result).to eq('test')
61
+ assert_equal('test', result)
62
62
  end
63
63
  end
64
64
 
65
65
  context "local_variable_filter" do
66
- it "not inspect String, Hash, Array, Set, Numeric, TrueClass, FalseClass, NilClass" do
66
+ should "not inspect String, Hash, Array, Set, Numeric, TrueClass, FalseClass, NilClass" do
67
67
  [
68
68
  ['test', String],
69
69
  [{ a: 1 }, Hash],
@@ -75,46 +75,46 @@ module ExceptionHandling
75
75
  [nil, NilClass]
76
76
  ].each do |object, expected_class|
77
77
  result = HoneybadgerCallbacks.send(:local_variable_filter, :variable_name, object, [])
78
- expect(result.is_a?(expected_class)).to be_truthy
78
+ assert result.is_a?(expected_class), "Expected #{expected_class.name} but got #{result.class.name}"
79
79
  end
80
80
  end
81
81
 
82
- it "inspect other classes" do
82
+ should "inspect other classes" do
83
83
  result = HoneybadgerCallbacks.send(:local_variable_filter, :variable_name, TestPoroWithAttribute.new, ['password'])
84
- expect(result).to match(/#<ExceptionHandling::TestPoroWithAttribute:.* @test_attribute="test">/)
84
+ assert_match(/#<ExceptionHandling::HoneybadgerCallbacksTest::TestPoroWithAttribute:.* @test_attribute="test">/, result)
85
85
  end
86
86
 
87
87
  context "when inspect raises exceptions" do
88
- it "handle exceptions for objects" do
88
+ should "handle exceptions for objects" do
89
89
  result = HoneybadgerCallbacks.send(:local_variable_filter, :variable_name, TestRaiseOnInspect.new, ['password'])
90
- expect(result).to eq("#<ExceptionHandling::TestRaiseOnInspect [error 'RuntimeError: some error' while calling #inspect]>")
90
+ assert_equal "#<ExceptionHandling::HoneybadgerCallbacksTest::TestRaiseOnInspect [error 'RuntimeError: some error' while calling #inspect]>", result
91
91
  end
92
92
 
93
- it "handle exceptions for objects responding to id" do
93
+ should "handle exceptions for objects responding to id" do
94
94
  result = HoneybadgerCallbacks.send(:local_variable_filter, :variable_name, TestRaiseOnInspectWithId.new, ['password'])
95
- expect(result).to eq("#<ExceptionHandling::TestRaiseOnInspectWithId @id=123 [error 'RuntimeError: some error' while calling #inspect]>")
95
+ assert_equal "#<ExceptionHandling::HoneybadgerCallbacksTest::TestRaiseOnInspectWithId @id=123 [error 'RuntimeError: some error' while calling #inspect]>", result
96
96
  end
97
97
 
98
- it "handle exceptions for objects responding to to_pk" do
98
+ should "handle exceptions for objects responding to to_pik" do
99
99
  result = HoneybadgerCallbacks.send(:local_variable_filter, :variable_name, TestRaiseOnInspectWithToPk.new, ['password'])
100
- expect(result).to eq("#<ExceptionHandling::TestRaiseOnInspectWithToPk @pk=SomeRecord-123 [error 'RuntimeError: some error' while calling #inspect]>")
100
+ assert_equal "#<ExceptionHandling::HoneybadgerCallbacksTest::TestRaiseOnInspectWithToPk @pk=SomeRecord-123 [error 'RuntimeError: some error' while calling #inspect]>", result
101
101
  end
102
102
  end
103
103
 
104
104
  context "not inspect objects that contain filter keys" do
105
- it "use to_pk if available, even if id is available" do
105
+ should "use to_pk if available, even if id is available" do
106
106
  result = HoneybadgerCallbacks.send(:local_variable_filter, :variable_name, TestPoroWithFilteredAttributePkAndId.new, ['password'])
107
- expect(result).to match(/#<ExceptionHandling::TestPoroWithFilteredAttributePkAndId @pk=TestPoroWithFilteredAttributePkAndId_1, \[FILTERED\]>/)
107
+ assert_match(/#<ExceptionHandling::HoneybadgerCallbacksTest::TestPoroWithFilteredAttributePkAndId @pk=TestPoroWithFilteredAttributePkAndId_1, \[FILTERED\]>/, result)
108
108
  end
109
109
 
110
- it "use id if to_pk is not available" do
110
+ should "use id if to_pk is not available" do
111
111
  result = HoneybadgerCallbacks.send(:local_variable_filter, :variable_name, TestPoroWithFilteredAttributeAndId.new, ['password'])
112
- expect(result).to match(/#<ExceptionHandling::TestPoroWithFilteredAttributeAndId @id=1, \[FILTERED\]>/)
112
+ assert_match(/#<ExceptionHandling::HoneybadgerCallbacksTest::TestPoroWithFilteredAttributeAndId @id=1, \[FILTERED\]>/, result)
113
113
  end
114
114
 
115
- it "print the object name if no id or to_pk" do
115
+ should "print the object name if no id or to_pk" do
116
116
  result = HoneybadgerCallbacks.send(:local_variable_filter, :variable_name, TestPoroWithFilteredAttribute.new, ['password'])
117
- expect(result).to match(/#<ExceptionHandling::TestPoroWithFilteredAttribute \[FILTERED\]>/)
117
+ assert_match(/#<ExceptionHandling::HoneybadgerCallbacksTest::TestPoroWithFilteredAttribute \[FILTERED\]>/, result)
118
118
  end
119
119
  end
120
120
  end
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../spec_helper', __dir__)
3
+ require File.expand_path('../../test_helper', __dir__)
4
4
 
5
5
  module ExceptionHandling
6
- describe LogErrorStub do
6
+ class LogErrorStubTest < ActiveSupport::TestCase
7
7
 
8
8
  include LogErrorStub
9
9
 
10
10
  context "while running tests" do
11
- before do
11
+ setup do
12
12
  setup_log_error_stub
13
13
  end
14
14
 
15
- after do
15
+ teardown do
16
16
  teardown_log_error_stub
17
17
  end
18
18
 
19
- it "raise an error when log_error and log_warning are called" do
19
+ should "raise an error when log_error and log_warning are called" do
20
20
  begin
21
21
  ExceptionHandling.log_error("Something happened")
22
22
  flunk
23
23
  rescue Exception => ex # LogErrorStub::UnexpectedExceptionLogged => ex
24
- expect(ex.to_s.starts_with?("StandardError: Something happened")).to be_truthy
24
+ assert ex.to_s.starts_with?("StandardError: Something happened"), ex.to_s
25
25
  end
26
26
 
27
27
  begin
@@ -31,16 +31,16 @@ module ExceptionHandling
31
31
  begin
32
32
  ExceptionHandling.log_error(ex)
33
33
  rescue LogErrorStub::UnexpectedExceptionLogged => ex
34
- expect(ex.to_s.starts_with?("RaisedError: This should raise")).to be_truthy
34
+ assert ex.to_s.starts_with?("RaisedError: This should raise"), ex.to_s
35
35
  end
36
36
  end
37
37
  end
38
38
 
39
- it "allow for the regex specification of an expected exception to be ignored" do
39
+ should "allow for the regex specification of an expected exception to be ignored" do
40
40
  exception_pattern = /StandardError: This is a test error/
41
- expect(exception_whitelist).to be_nil # test that exception expectations are cleared
41
+ assert_nil exception_whitelist # test that exception expectations are cleared
42
42
  expects_exception(exception_pattern)
43
- expect(exception_whitelist[0][0]).to eq(exception_pattern)
43
+ assert_equal exception_pattern, exception_whitelist[0][0]
44
44
  begin
45
45
  ExceptionHandling.log_error("This is a test error")
46
46
  rescue StandardError
@@ -48,11 +48,11 @@ module ExceptionHandling
48
48
  end
49
49
  end
50
50
 
51
- it "allow for the string specification of an expected exception to be ignored" do
51
+ should "allow for the string specification of an expected exception to be ignored" do
52
52
  exception_pattern = "StandardError: This is a test error"
53
- expect(exception_whitelist).to be_nil # test that exception expectations are cleared
53
+ assert_nil exception_whitelist # test that exception expectations are cleared
54
54
  expects_exception(exception_pattern)
55
- expect(exception_whitelist[0][0]).to eq(exception_pattern)
55
+ assert_equal exception_pattern, exception_whitelist[0][0]
56
56
  begin
57
57
  ExceptionHandling.log_error("This is a test error")
58
58
  rescue StandardError
@@ -60,9 +60,9 @@ module ExceptionHandling
60
60
  end
61
61
  end
62
62
 
63
- it "allow multiple errors to be ignored" do
63
+ should "allow multiple errors to be ignored" do
64
64
  class IgnoredError < StandardError; end
65
- expect(exception_whitelist).to be_nil # test that exception expectations are cleared
65
+ assert_nil exception_whitelist # test that exception expectations are cleared
66
66
  expects_exception(/StandardError: This is a test error/)
67
67
  expects_exception(/IgnoredError: This should be ignored/)
68
68
  ExceptionHandling.log_error("This is a test error")
@@ -73,7 +73,7 @@ module ExceptionHandling
73
73
  end
74
74
  end
75
75
 
76
- it "expect exception twice if declared twice" do
76
+ should "expect exception twice if declared twice" do
77
77
  expects_exception(/StandardError: ERROR: I love lamp/)
78
78
  expects_exception(/StandardError: ERROR: I love lamp/)
79
79
  ExceptionHandling.log_error("ERROR: I love lamp")
@@ -82,39 +82,23 @@ module ExceptionHandling
82
82
  end
83
83
 
84
84
  context "teardown_log_error_stub" do
85
- before do
86
- RSpec.configure do |config|
87
- config.mock_with :rspec do |mocks|
88
- mocks.verify_partial_doubles = false
89
- end
90
- end
91
- end
92
-
93
- after do
94
- RSpec.configure do |config|
95
- config.mock_with :rspec do |mocks|
96
- mocks.verify_partial_doubles = true
97
- end
98
- end
99
- end
100
-
101
- it "support MiniTest framework for adding a failure" do
85
+ should "support MiniTest framework for adding a failure" do
102
86
  expects_exception(/foo/)
103
87
 
104
- expect(self).to receive(:is_mini_test?) { true }
88
+ mock(self).is_mini_test?.returns { true }
105
89
 
106
- expect(self).to receive(:flunk).with("log_error expected 1 times with pattern: 'foo' found 0")
90
+ mock(self).flunk("log_error expected 1 times with pattern: 'foo' found 0")
107
91
  teardown_log_error_stub
108
92
 
109
93
  self.exception_whitelist = nil
110
94
  end
111
95
 
112
- it "support Test::Unit framework for adding a failure" do
96
+ should "support Test::Unit framework for adding a failure" do
113
97
  expects_exception(/foo/)
114
98
 
115
- expect(self).to receive(:is_mini_test?) { false }
99
+ mock(self).is_mini_test?.returns { false }
116
100
 
117
- expect(self).to receive(:add_failure).with("log_error expected 1 times with pattern: 'foo' found 0")
101
+ mock(self).add_failure("log_error expected 1 times with pattern: 'foo' found 0")
118
102
  teardown_log_error_stub
119
103
 
120
104
  self.exception_whitelist = nil
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../spec_helper', __dir__)
4
- require 'rails-dom-testing'
3
+ require File.expand_path('../../test_helper', __dir__)
5
4
 
6
5
  module ExceptionHandling
7
- describe Mailer do
6
+ class MailerTest < ActionMailer::TestCase
8
7
 
9
8
  include ::Rails::Dom::Testing::Assertions::SelectorAssertions
9
+ tests ExceptionHandling::Mailer
10
10
 
11
11
  def dont_stub_log_error
12
12
  true
13
13
  end
14
14
 
15
15
  context "ExceptionHandling::Mailer" do
16
- before do
16
+ setup do
17
17
  ExceptionHandling.email_environment = 'Test'
18
18
  ExceptionHandling.sender_address = %("Test Exception Mailer" <null_exception@invoca.com>)
19
19
  ExceptionHandling.exception_recipients = ['test_exception@invoca.com']
@@ -21,22 +21,22 @@ module ExceptionHandling
21
21
  end
22
22
 
23
23
  context "log_parser_exception_notification" do
24
- it "send with string" do
24
+ should "send with string" do
25
25
  result = ExceptionHandling::Mailer.log_parser_exception_notification("This is my fake error", "My Fake Subj").deliver_now
26
- expect(result.subject).to eq("Test exception: My Fake Subj: This is my fake error")
27
- expect(result.body.to_s).to match(/This is my fake error/)
26
+ assert_equal "Test exception: My Fake Subj: This is my fake error", result.subject
27
+ assert_match(/This is my fake error/, result.body.to_s)
28
28
  assert_emails 1
29
29
  end
30
30
  end
31
31
 
32
32
  context "escalation_notification" do
33
- before do
33
+ setup do
34
34
  def document_root_element
35
35
  @body_html.root
36
36
  end
37
37
  end
38
38
 
39
- it "send all the information" do
39
+ should "send all the information" do
40
40
  ExceptionHandling.email_environment = 'Staging Full'
41
41
  ExceptionHandling.server_name = 'test-fe3'
42
42
 
@@ -46,8 +46,8 @@ module ExceptionHandling
46
46
  result = ActionMailer::Base.deliveries.last
47
47
  @body_html = Nokogiri::HTML(result.body.to_s)
48
48
  assert_equal_with_diff ['test_escalation@invoca.com'], result.to
49
- expect(result[:from].formatted).to eq(["Test Escalation Mailer <null_escalation@invoca.com>"])
50
- expect(result.subject).to eq("Staging Full Escalation: Your Favorite <b>Feature<b> Failed")
49
+ assert_equal ["Test Escalation Mailer <null_escalation@invoca.com>"], result[:from].formatted
50
+ assert_equal "Staging Full Escalation: Your Favorite <b>Feature<b> Failed", result.subject
51
51
  assert_select "title", "Exception Escalation"
52
52
  assert_select "html" do
53
53
  assert_select "body br", { count: 4 }, result.body.to_s # plus 1 for the multiline summary
@@ -60,13 +60,13 @@ module ExceptionHandling
60
60
  end
61
61
  end
62
62
 
63
- it "use defaults for missing fields" do
63
+ should "use defaults for missing fields" do
64
64
  result = ExceptionHandling::Mailer.escalation_notification("Your Favorite Feature Failed", error_string: "It failed because of an error\n More Info")
65
65
  @body_html = Nokogiri::HTML(result.body.to_s)
66
66
 
67
67
  assert_equal_with_diff ['test_escalation@invoca.com'], result.to
68
- expect(result.from).to eq(["null_escalation@invoca.com"])
69
- expect(result.subject).to eq('Test Escalation: Your Favorite Feature Failed')
68
+ assert_equal ["null_escalation@invoca.com"], result.from
69
+ assert_equal 'Test Escalation: Your Favorite Feature Failed', result.subject
70
70
  assert_select "html" do
71
71
  assert_select "body i", true, result.body.to_s do |is|
72
72
  assert_select is, "i", 'no error #'
@@ -75,11 +75,11 @@ module ExceptionHandling
75
75
  end
76
76
 
77
77
  context "ExceptionHandling.escalate_to_production_support" do
78
- before do
78
+ setup do
79
79
  Time.now_override = Time.parse('1986-5-21 4:17 am UTC')
80
80
  end
81
81
 
82
- it "notify production support" do
82
+ should "notify production support" do
83
83
  subject = "Runtime Error found!"
84
84
  exception = RuntimeError.new("Test")
85
85
  recipients = ["prodsupport@example.com"]
@@ -87,11 +87,12 @@ module ExceptionHandling
87
87
  ExceptionHandling.production_support_recipients = recipients
88
88
  ExceptionHandling.last_exception_timestamp = Time.now.to_i
89
89
 
90
- expect(ExceptionHandling).to receive(:escalate).with(subject, exception, Time.now.to_i, recipients)
90
+ mock(ExceptionHandling).escalate(subject, exception, Time.now.to_i, recipients)
91
91
  ExceptionHandling.escalate_to_production_support(exception, subject)
92
92
  end
93
93
  end
94
94
  end
95
95
  end
96
+
96
97
  end
97
98
  end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../test_helper', __dir__)
4
+
5
+ require "exception_handling/testing"
6
+
7
+ module ExceptionHandling
8
+ class MethodsTest < ActiveSupport::TestCase
9
+ include ExceptionHelpers
10
+
11
+ def dont_stub_log_error
12
+ true
13
+ end
14
+
15
+ context "ExceptionHandling.Methods" do
16
+ setup do
17
+ @controller = Testing::ControllerStub.new
18
+ ExceptionHandling.stub_handler = nil
19
+ end
20
+
21
+ should "set the around filter" do
22
+ assert_equal :set_current_controller, Testing::ControllerStub.around_filter_method
23
+ assert_nil ExceptionHandling.current_controller
24
+ @controller.simulate_around_filter do
25
+ assert_equal @controller, ExceptionHandling.current_controller
26
+ end
27
+ assert_nil ExceptionHandling.current_controller
28
+ end
29
+
30
+ should "use the current_controller when available" do
31
+ capture_notifications
32
+
33
+ mock(ExceptionHandling.logger).fatal(/blah/, anything)
34
+ @controller.simulate_around_filter do
35
+ ExceptionHandling.log_error(ArgumentError.new("blah"))
36
+ assert_equal 1, sent_notifications.size, sent_notifications.inspect
37
+ assert_match(@controller.request.request_uri, sent_notifications.last.enhanced_data['request'].to_s)
38
+ end
39
+ end
40
+
41
+ should "report long running controller action" do
42
+ assert_equal 2, @controller.send(:long_controller_action_timeout)
43
+ mock(ExceptionHandling).log_error(/Long controller action detected in #{@controller.class.name.split("::").last}::test_action/, anything, anything)
44
+ @controller.simulate_around_filter do
45
+ sleep(3)
46
+ end
47
+ end
48
+
49
+ should "not report long running controller actions if it is less than the timeout" do
50
+ assert_equal 2, @controller.send(:long_controller_action_timeout)
51
+ stub(ExceptionHandling).log_error { flunk "Should not timeout" }
52
+ @controller.simulate_around_filter do
53
+ sleep(1)
54
+ end
55
+ end
56
+
57
+ should "default long running controller action(300/30 for test/prod)" do
58
+ class DummyController
59
+ include ExceptionHandling::Methods
60
+ end
61
+
62
+ controller = DummyController.new
63
+
64
+ Rails.env = 'production'
65
+ assert_equal 30, controller.send(:long_controller_action_timeout)
66
+
67
+ Rails.env = 'test'
68
+ assert_equal 300, controller.send(:long_controller_action_timeout)
69
+ end
70
+
71
+ context "#log_warning" do
72
+ should "be available to the controller" do
73
+ assert_equal true, @controller.methods.include?(:log_warning)
74
+ end
75
+
76
+ should "call ExceptionHandling#log_warning" do
77
+ mock(ExceptionHandling).log_warning("Hi mom")
78
+ @controller.send(:log_warning, "Hi mom")
79
+ end
80
+ end
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../test_helper', __dir__)
4
+
5
+ module ExceptionHandling
6
+ class SensuTest < ActiveSupport::TestCase
7
+ context "#generate_event" do
8
+ should "create an event" do
9
+ mock(ExceptionHandling::Sensu).send_event(name: "world_is_ending", output: "stick head between knees and kiss ass goodbye", status: 1)
10
+
11
+ ExceptionHandling::Sensu.generate_event("world_is_ending", "stick head between knees and kiss ass goodbye")
12
+ end
13
+
14
+ should "add the sensu prefix" do
15
+ ExceptionHandling.sensu_prefix = "cnn_"
16
+
17
+ mock(ExceptionHandling::Sensu).send_event(name: "cnn_world_is_ending", output: "stick head between knees and kiss ass goodbye", status: 1)
18
+
19
+ ExceptionHandling::Sensu.generate_event("world_is_ending", "stick head between knees and kiss ass goodbye")
20
+ end
21
+
22
+ should "allow the level to be set to critical" do
23
+ mock(ExceptionHandling::Sensu).send_event(name: "world_is_ending", output: "stick head between knees and kiss ass goodbye", status: 2)
24
+
25
+ ExceptionHandling::Sensu.generate_event("world_is_ending", "stick head between knees and kiss ass goodbye", :critical)
26
+ end
27
+
28
+ should "error if an invalid level is supplied" do
29
+ dont_allow(ExceptionHandling::Sensu).send_event
30
+
31
+ assert_raise(RuntimeError, "Invalid alert level") do
32
+ ExceptionHandling::Sensu.generate_event("world_is_ending", "stick head between knees and kiss ass goodbye", :hair_on_fire)
33
+ end
34
+ end
35
+ end
36
+
37
+ context "#send_event" do
38
+ setup do
39
+ @event = { name: "world_is_ending", output: "stick head between knees and kiss ass goodbye", status: 1 }
40
+ @socket = SocketStub.new
41
+ end
42
+
43
+ should "send event json to sensu client" do
44
+ mock.any_instance_of(Addrinfo).connect.with_any_args { @socket }
45
+
46
+ ExceptionHandling::Sensu.send_event(@event)
47
+
48
+ assert_equal @event.to_json, @socket.sent.first
49
+ end
50
+ end
51
+ end
52
+ end