Sha256: 070892ef172d9f7f851f2941d36c07bd0de6f30cfac2fad1ff07b21650ddcfeb

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

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

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

    begin
      block.call
      RSpec::Mocks::verify
      true
    rescue RSpec::Mocks::MockExpectationError => e
      false
    end
  end
end

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

  match do |block|
    expect(Reactor::Event).to receive(:publish).exactly(events.count).times do |event, data|
      match = events.select { |e| (e.is_a?(Hash) ? e.keys.first : e) == event }.first
      expect(match).to be_present

      expected = match.is_a?(Hash) ? match.values.first : {match => {}}
      expected.each do |key, value|
        expect(value).to eq(expected[key])
      end
    end

    begin
      block.call
      RSpec::Mocks::verify
      true
    rescue RSpec::Mocks::MockExpectationError => e
      false
    end
  end
end

RSpec::Matchers.define :subscribe_to do |name, data = {}, &expectations|
  supports_block_expectations

  match do
    expectations.call if expectations.present?
    Reactor::Event.publish(name, data)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reactor-0.8.2 lib/reactor/testing/matchers.rb
reactor-0.8.1 lib/reactor/testing/matchers.rb