I've been trying for a while to write a custom matcher for my gem Wisper, which provides pub/sub for Ruby objects.
Wisper uses `public_send` to publish an event to subscribed listeners.
At the moment without a custom matcher I can subscribe a double to a publisher and assert the method (i.e. event) is received.
publisher = Class.new do
include Wisper::Publisher
def execute
broadcast(:successful) # this will do `public_send(:successful)` on every subscriber
end
end.new
subscriber = double
publisher.subscribe(subscriber)
expect(subscriber).to receive(:successful)
publisher.execute
BUT... what I really want to do is this:
publisher = ...
expect(publisher).to publisher(:successful)
publisher.execute
I've tried a few things, but I can't seem to get it to work unless `expect` is given a block in which the publisher's `execute` method is called, i.e.
expect { publisher.execute }.to broadcast(:successful)
I'd like something more akin to `receive` where the actual assertion does not have to happen within the `expect`, but can happen later.
Any pointers would be gratefully received (no pun intended). Also I'm unsure of the difference between a matcher and expectation, are they the same or different?
- Kris.