Sha256: 634a989a71088b63979bdc86731eac046d5cf633b4d995b1601c1bea5559e4ef

Contents?: true

Size: 956 Bytes

Versions: 13

Compression:

Stored size: 956 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

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

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
reactor-0.5.2 lib/reactor/testing/matchers.rb
reactor-0.5.1 lib/reactor/testing/matchers.rb
reactor-0.5.0 lib/reactor/testing/matchers.rb
reactor-0.4.7 lib/reactor/testing/matchers.rb
reactor-0.4.6 lib/reactor/testing/matchers.rb
reactor-0.4.5 lib/reactor/testing/matchers.rb
reactor-0.4.4 lib/reactor/testing/matchers.rb
reactor-0.4.3 lib/reactor/testing/matchers.rb
reactor-0.4.2 lib/reactor/testing/matchers.rb
reactor-0.4.0 lib/reactor/testing/matchers.rb
reactor-0.3.2 lib/reactor/testing/matchers.rb
reactor-0.3.1 lib/reactor/testing/matchers.rb
reactor-0.3.0 lib/reactor/testing/matchers.rb