spec/arborist/observer_spec.rb in arborist-0.0.1.pre20160829140603 vs spec/arborist/observer_spec.rb in arborist-0.0.1.pre20161005112841

- old
+ new

@@ -41,9 +41,42 @@ expect( observer.subscriptions ).to be_an( Array ) expect( observer.subscriptions.length ).to eq( 2 ) end + it "can specify criteria for events" do + observer = described_class.new( "testing observer" ) do + subscribe to: 'node.up', where: { type: 'host' } + end + + expect( observer.subscriptions ).to be_an( Array ) + expect( observer.subscriptions ).to include( a_hash_including(criteria: {type: 'host'}) ) + expect( observer.subscriptions.length ).to eq( 1 ) + end + + + it "can specify negative criteria for events" do + observer = described_class.new( "testing observer" ) do + subscribe to: 'node.up', exclude: { type: 'host' } + end + + expect( observer.subscriptions ).to be_an( Array ) + expect( observer.subscriptions ).to include( a_hash_including(exclude: {type: 'host'}) ) + expect( observer.subscriptions.length ).to eq( 1 ) + end + + + it "can specify a subscription node other than the root" do + observer = described_class.new( "testing observer" ) do + subscribe to: 'node.down', on: 'dmz-gateway' + end + + expect( observer.subscriptions ).to be_an( Array ) + expect( observer.subscriptions ).to include( a_hash_including(identifier: 'dmz-gateway') ) + expect( observer.subscriptions.length ).to eq( 1 ) + end + + it "can specify an action to run when a subscribed event is received" do observer = described_class.new( "testing observer" ) do action do |event| # no-op end