Skip to content

Commit

Permalink
added filters all over the place so tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
auxesis committed Dec 24, 2009
1 parent 644243a commit 6038618
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
13 changes: 13 additions & 0 deletions spec/notifier_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

it "should have a simple interface to start the notifier" do
options = { :notifiers => {},
:filters => [],
:log => MockLogger.new,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
Expand All @@ -17,6 +18,7 @@

it "should log when loading a notifier" do
options = { :notifiers => {:testmailer => {}},
:filters => [],
:log => MockLogger.new,
:notifier_directories => [File.join(File.dirname(__FILE__),'notifier-directories', 'spoons')],
:persistence => {:backend => :mock_persistence_backend,
Expand All @@ -27,6 +29,7 @@

it "should warn if a specified notifier doesn't exist" do
options = { :notifiers => {:nonexistant => {}},
:filters => [],
:log => MockLogger.new,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
Expand All @@ -36,6 +39,7 @@

it "should give precedence to notifiers in user-specified notifier directories" do
options = { :notifiers => {:testmailer => {}},
:filters => [],
:log => MockLogger.new,
:notifier_directories => [File.join(File.dirname(__FILE__),'notifier-directories', 'spoons')],
:persistence => {:backend => :mock_persistence_backend,
Expand All @@ -50,6 +54,7 @@

it "should setup recipients from a list" do
options = { :notifiers => {},
:filters => [],
:log => MockLogger.new,
:recipients => [{:name => "Spoons McDoom"}],
:persistence => {:backend => :mock_persistence_backend,
Expand All @@ -65,6 +70,7 @@

it "should use beanstalkd as the default transport" do
options = { :notifiers => {},
:filters => [],
:log => MockLogger.new,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
Expand All @@ -74,6 +80,7 @@

it "should use a transport as specified in options" do
options = { :notifiers => {},
:filters => [],
:log => MockLogger.new,
:transport => {:backend => :beanstalkd},
:persistence => {:backend => :mock_persistence_backend,
Expand All @@ -84,6 +91,7 @@

it "should error if the specified transport doesn't exist" do
options = { :notifiers => {},
:filters => [],
:log => MockLogger.new,
:transport => {:backend => :nonexistant} }
lambda {
Expand All @@ -100,6 +108,7 @@
#

options = { :notifiers => {},
:filters => [],
:log => MockLogger.new,
:transport => {:backend => :mock_transport,
:basedir => File.join(File.dirname(__FILE__), 'transports')},
Expand Down Expand Up @@ -129,6 +138,7 @@
#

options = { :notifiers => {},
:filters => ['ok'],
:log => MockLogger.new,
:transport => {:backend => :mock_transport,
:basedir => File.join(File.dirname(__FILE__), 'transports')},
Expand Down Expand Up @@ -158,6 +168,7 @@
#

options = { :notifiers => {},
:filters => ['any_parents_failed'],
:log => MockLogger.new,
:transport => {:backend => :mock_transport,
:basedir => File.join(File.dirname(__FILE__), 'transports')},
Expand Down Expand Up @@ -188,6 +199,7 @@

it "should load a persistence backend as specified in options" do
options = { :notifiers => {},
:filters => [],
:log => MockLogger.new,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
Expand All @@ -197,6 +209,7 @@

it "should raise if the specified persistence backend doesn't exist" do
options = { :notifiers => {},
:filters => [],
:log => MockLogger.new,
:persistence => {:backend => :nonexistant} }
lambda {
Expand Down
20 changes: 8 additions & 12 deletions spec/notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
}.should raise_error(RuntimeError)
end

it "should have a blank recipients list if none specified" do
n = Flapjack::NotifierEngine.new(:log => MockLogger.new)
n.recipients.should_not be_nil
n.recipients.size.should == 0
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/
Expand All @@ -38,9 +32,10 @@
result = Flapjack::Transport::Result.new(:result => {:check_id => 12345})

n = Flapjack::NotifierEngine.new(:log => MockLogger.new,
:notifiers => [mock_notifier],
:recipients => [OpenStruct.new({:name => "John Doe"})])
n.notify!(:result => result, :event => true)
:notifiers => [mock_notifier])
n.notify!(:result => result,
:event => true,
:recipients => [OpenStruct.new({:name => "John Doe"})])
end

it "should log notification on each notifier" do
Expand All @@ -50,9 +45,10 @@
result = Flapjack::Transport::Result.new(:result => {:check_id => 12345})

n = Flapjack::NotifierEngine.new(:log => MockLogger.new,
:notifiers => [mock_notifier],
:recipients => [OpenStruct.new({:name => "John Doe"})])
n.notify!(:result => result, :event => true)
: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
Expand Down
3 changes: 3 additions & 0 deletions spec/transports/beanstalkd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
@beanstalk = Beanstalk::Connection.new('localhost:11300', 'results')
rescue => e
# give helpful error messages to people unfamiliar with the test suite
puts
puts "You need to have an instance of beanstalkd running locally to run these tests!"
puts
raise
end
}.should_not raise_error
Expand All @@ -24,6 +26,7 @@
end

options = { :notifiers => {},
:filters => [],
:log => MockLogger.new,
:transport => {:backend => :beanstalkd},
:persistence => {:backend => :mock_persistence_backend,
Expand Down

0 comments on commit 6038618

Please sign in to comment.