From 0053c17bba34090083a34395657ff1ba1616e213 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Mon, 5 Oct 2015 13:38:36 -0700 Subject: Fix dispatch when there are different receivers with different numbers of arguments. Fixes https://github.com/chef/chef-dk/issues/546) --- spec/unit/event_dispatch/dispatcher_spec.rb | 47 +++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'spec/unit/event_dispatch') 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 -- cgit v1.2.1