Sha256: 228bfeda3905c70eeb8a6630c4026c10b34f8a1afddad8083ba63568456641db

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

#
# DRY up strict event & data assertions.
#
# Example:
#
#  expect { some_thing }.to publish_event(:some_event, actor: this_user, target: this_object)
#
RSpec::Matchers.define :publish_event do |name, data = {}|
  supports_block_expectations

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

    allow(Reactor::Event).to receive(:publish)

    block.call

    expect(Reactor::Event).to have_received(:publish).with(name, a_hash_including(defaults.merge(data))).at_least(:once)
  end
end


#
# DRY up multi-event assertions. Unfortunately can't test key-values with this at the moment.
#
# Example:
#
#  expect { some_thing }.to publish_events(:some_event, :another_event)
#
RSpec::Matchers.define :publish_events do |*names|
  supports_block_expectations

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

    allow(Reactor::Event).to receive(:publish)

    block.call

    names.each do |name|
      expect(Reactor::Event).to have_received(:publish).with(name, a_hash_including(defaults)).at_least(:once)
    end
  end
end

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reactor-2.0.1 lib/reactor/testing/matchers.rb
reactor-2.0.0 lib/reactor/testing/matchers.rb
reactor-1.0.2 lib/reactor/testing/matchers.rb
reactor-1.0.1 lib/reactor/testing/matchers.rb
reactor-1.0.0 lib/reactor/testing/matchers.rb
reactor-0.19.0 lib/reactor/testing/matchers.rb
reactor-0.18.0 lib/reactor/testing/matchers.rb
reactor-0.17.0 lib/reactor/testing/matchers.rb