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.
https://github.com/krisleech/wisper/blob/rspec-matcher/lib/wisper/rspec/matchers.rb
https://github.com/krisleech/wisper/blob/rspec-matcher/spec/lib/wisper/rspec/matchers_spec.rb
<- this shows the passing and failing spec (prefer syntax)
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.
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/568084ec-a394-4c30-9dc2-85340176ee68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.