Sha256: 8dc0b914b93b8a7f44ff62559da81ffe454022bec395246dae780030de385d08

Contents?: true

Size: 774 Bytes

Versions: 1

Compression:

Stored size: 774 Bytes

Contents

RSpec::Matchers.define :publish_event do |name, data = {}|

  match do |block|
    defaults = {:actor => anything}
    Reactor::Event.should_receive(:publish).with(name, hash_including(defaults.merge(data)))
    block.call
  end
end

RSpec::Matchers.define :publish_events do |*events|

  match do |block|
    defaults = {:actor => anything, at: anything, target: anything}

    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reactor-0.2.10 lib/reactor/testing/matchers.rb