summaryrefslogtreecommitdiff
path: root/spec/unit/event_dispatch
diff options
context:
space:
mode:
authorRanjib Dey <ranjib@pagerduty.com>2015-06-23 23:13:12 -0700
committerRanjib Dey <ranjib@pagerduty.com>2015-06-24 10:12:45 -0700
commit720f3331f794a2ad31bee2b1113ac99fada85389 (patch)
tree4f03dfd86d9fb543cb2eaf1b6a4c3848d356b11f /spec/unit/event_dispatch
parent9f0ea8aa0ec05819e242dedaa85fe731dca3146c (diff)
parentab34e3cd83d545b5da19113d723eeebcab1e77e2 (diff)
downloadchef-720f3331f794a2ad31bee2b1113ac99fada85389.tar.gz
Merge remote-tracking branch 'origin/master' into chef_handler
Diffstat (limited to 'spec/unit/event_dispatch')
-rw-r--r--spec/unit/event_dispatch/dsl_spec.rb37
1 files changed, 25 insertions, 12 deletions
diff --git a/spec/unit/event_dispatch/dsl_spec.rb b/spec/unit/event_dispatch/dsl_spec.rb
index e30b1cb40e..f467ea81ea 100644
--- a/spec/unit/event_dispatch/dsl_spec.rb
+++ b/spec/unit/event_dispatch/dsl_spec.rb
@@ -20,8 +20,29 @@ require 'spec_helper'
require 'chef/event_dispatch/dsl'
describe Chef::EventDispatch::DSL do
+ let(:events) do
+ Chef::EventDispatch::Dispatcher.new
+ end
+
+ let(:run_context) do
+ Chef::RunContext.new(Chef::Node.new, nil, events)
+ end
+
+ before do
+ Chef.set_run_context(run_context)
+ end
+
+ after do
+ Chef.reset!
+ end
+
subject{ described_class.new('test') }
+ it 'set handler name' do
+ subject.on(:run_started) {}
+ expect(events.subscribers.first.name).to eq('test')
+ end
+
it 'raise error when invalid event type is supplied' do
expect do
subject.on(:foo_bar) {}
@@ -30,12 +51,10 @@ describe Chef::EventDispatch::DSL do
it 'register user hooks against valid event type' do
subject.on(:run_failed) {'testhook'}
- expect(Chef::Config[:event_handlers].first.run_failed).to eq('testhook')
+ expect(events.subscribers.first.run_failed).to eq('testhook')
end
it 'preserve state across event hooks' do
- Chef::Config.reset!
- node = Chef::Node.new
calls = []
Chef.event_handler do
on :resource_updated do
@@ -45,17 +64,13 @@ describe Chef::EventDispatch::DSL do
calls << :started
end
end
- events = Chef::EventDispatch::Dispatcher.new(*Chef::Config[:event_handlers])
- rc = Chef::RunContext.new(node, nil, events)
- resource = Chef::Resource::RubyBlock.new('foo', rc)
+ resource = Chef::Resource::RubyBlock.new('foo', run_context)
resource.block { }
resource.run_action(:run)
expect(calls).to eq([:started, :updated])
end
it 'preserve instance variables across handler callbacks' do
- Chef::Config.reset!
- node = Chef::Node.new
Chef.event_handler do
on :resource_action_start do
@ivar = [1]
@@ -64,11 +79,9 @@ describe Chef::EventDispatch::DSL do
@ivar << 2
end
end
- events = Chef::EventDispatch::Dispatcher.new(*Chef::Config[:event_handlers])
- rc = Chef::RunContext.new(node, nil, events)
- resource = Chef::Resource::RubyBlock.new('foo', rc)
+ resource = Chef::Resource::RubyBlock.new('foo', run_context)
resource.block { }
resource.run_action(:run)
- expect(Chef::Config[:event_handlers].first.instance_variable_get(:@ivar)).to eq([1, 2])
+ expect(events.subscribers.first.instance_variable_get(:@ivar)).to eq([1, 2])
end
end