forked from flapjack/flapjack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotifier_spec.rb
57 lines (44 loc) · 1.97 KB
/
notifier_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require File.join(File.dirname(__FILE__), '..', 'lib', 'flapjack', 'notifier_engine')
require File.join(File.dirname(__FILE__), '..', 'lib', 'flapjack', 'transports', 'result')
require File.join(File.dirname(__FILE__), 'helpers')
describe "running the notifier" do
before(:each) do
end
it "should complain if no logger has been specified" do
lambda {
n = Flapjack::NotifierEngine.new
}.should raise_error(RuntimeError)
end
it "should warn if no notifiers have been specified" do
n = Flapjack::NotifierEngine.new(:log => MockLogger.new)
n.log.messages.last.should =~ /no notifiers/
end
it "should log when adding a new notifier" do
mock_notifier = mock("MockFlapjack::NotifierEngine")
n = Flapjack::NotifierEngine.new(:log => MockLogger.new,
:notifiers => [mock_notifier])
n.log.messages.last.should =~ /using the (.+) notifier/
end
it "should call notify on each notifier when notifying" do
mock_notifier = mock("MockFlapjack::NotifierEngine")
mock_notifier.should_receive(:notify)
result = Flapjack::Transport::Result.new(:result => {:check_id => 12345})
n = Flapjack::NotifierEngine.new(:log => MockLogger.new,
:notifiers => [mock_notifier])
n.notify!(:result => result,
:event => true,
:recipients => [OpenStruct.new({:name => "John Doe"})])
end
it "should log notification on each notifier" do
mock_notifier = mock("MockFlapjack::NotifierEngine")
mock_notifier.stub!(:notify)
result = Flapjack::Transport::Result.new(:result => {:check_id => 12345})
n = Flapjack::NotifierEngine.new(:log => MockLogger.new,
:notifiers => [mock_notifier])
n.notify!(:result => result,
:event => true,
:recipients => [OpenStruct.new({:name => "John Doe"})])
n.log.messages.last.should =~ /12345/
n.log.messages.last.should =~ /John Doe/
end
end