summaryrefslogtreecommitdiff
path: root/spec/unit/event_dispatch
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-10-05 13:38:36 -0700
committerJohn Keiser <john@johnkeiser.com>2015-10-05 13:38:36 -0700
commit0053c17bba34090083a34395657ff1ba1616e213 (patch)
tree3f0234a43a070b46eebf62ed1f68a2c423f61e2e /spec/unit/event_dispatch
parentdef2fe69b82fb8f0f5feb6634f63d6a3dc78ca85 (diff)
downloadchef-0053c17bba34090083a34395657ff1ba1616e213.tar.gz
Fix dispatch when there are different receivers
with different numbers of arguments. Fixes https://github.com/chef/chef-dk/issues/546)
Diffstat (limited to 'spec/unit/event_dispatch')
-rw-r--r--spec/unit/event_dispatch/dispatcher_spec.rb47
1 files changed, 45 insertions, 2 deletions
diff --git a/spec/unit/event_dispatch/dispatcher_spec.rb b/spec/unit/event_dispatch/dispatcher_spec.rb
index 1014feea89..5a06e1d6d1 100644
--- a/spec/unit/event_dispatch/dispatcher_spec.rb
+++ b/spec/unit/event_dispatch/dispatcher_spec.rb
@@ -73,8 +73,51 @@ describe Chef::EventDispatch::Dispatcher do
expect(event_sink.synchronized_cookbook_args).to eq ["apache2"]
end
end
-
end
-end
+ context "when two event sinks have different arguments for an event" do
+ let(:event_sink_1) do
+ Class.new(Chef::EventDispatch::Base) do
+ attr_reader :synchronized_cookbook_args
+ def synchronized_cookbook(cookbook_name)
+ @synchronized_cookbook_args = [cookbook_name]
+ end
+ end.new
+ end
+ let(:event_sink_2) do
+ Class.new(Chef::EventDispatch::Base) do
+ attr_reader :synchronized_cookbook_args
+ def synchronized_cookbook(cookbook_name, cookbook)
+ @synchronized_cookbook_args = [cookbook_name, cookbook]
+ end
+ end.new
+ end
+
+ context "and the one with fewer arguments comes first" do
+ before do
+ dispatcher.register(event_sink_1)
+ dispatcher.register(event_sink_2)
+ end
+ it "trims the arugment list" do
+ cookbook_version = double("cookbook_version")
+ dispatcher.synchronized_cookbook("apache2", cookbook_version)
+ expect(event_sink_1.synchronized_cookbook_args).to eq ["apache2"]
+ expect(event_sink_2.synchronized_cookbook_args).to eq ["apache2", cookbook_version]
+ end
+ end
+
+ context "and the one with fewer arguments comes last" do
+ before do
+ dispatcher.register(event_sink_2)
+ dispatcher.register(event_sink_1)
+ end
+ it "trims the arugment list" do
+ cookbook_version = double("cookbook_version")
+ dispatcher.synchronized_cookbook("apache2", cookbook_version)
+ expect(event_sink_1.synchronized_cookbook_args).to eq ["apache2"]
+ expect(event_sink_2.synchronized_cookbook_args).to eq ["apache2", cookbook_version]
+ end
+ end
+ end
+end