lib/reactor/testing/matchers.rb in reactor-0.2.9 vs lib/reactor/testing/matchers.rb in reactor-0.2.10

- old
+ new

@@ -5,20 +5,21 @@ Reactor::Event.should_receive(:publish).with(name, hash_including(defaults.merge(data))) block.call end end -RSpec::Matchers.define :publish_events do |*args| +RSpec::Matchers.define :publish_events do |*events| match do |block| - defaults = {:actor => anything} + defaults = {:actor => anything, at: anything, target: anything} - args.each do |event| - case event - when Symbol - Reactor::Event.should_receive(:publish).with(event, anything) - when Hash - Reactor::Event.should_receive(:publish).with(event.keys.first, hash_including(defaults.merge(event.values.first))) + Reactor::Event.should_receive(:publish).exactly(events.count).times.with do |event, data| + match = events.select { |e| (e.is_a?(Hash) ? e.keys.first : e) == event }.first + match.should be_present + + expected = match.is_a?(Hash) ? match.values.first : {match => {}} + expected.each do |key, value| + value.should == expected[key] end end block.call end end \ No newline at end of file