[rspec-devel] should_yield (is it needed?)

David Chelimsky dchelimsky at gmail.com
Tue Nov 10 20:00:22 EST 2009

On Fri, Nov 6, 2009 at 10:43 PM, Martin Emde <martin.emde at gmail.com> wrote:

> I have the code working for this but I wanted an opinion on making a patch.
> I sometimes have the need to expect that a method will yield a block it's
> given. Usually this means something like this:
>     yielded = false
>     subject.method { yielded = true }
>     yielded.should == true
> which is a bit tedious and ugly. My solution might be just as ugly, but I
> wanted to get feedback because it saves that tedious code.
>     subject.method(&should_yield)
> I wrote a few methods, that when called, return an object with #to_proc
> that expects that the proc is called (or not called). I have the following
> forms available fairly simply:
>     subject.method(&should_not_yield)
>     subject.method(&should_yield_with(object))
>     # Expects 3 yields, one with each argument
>     [1,2,3].each(&should_yield_each(1,2,3))
> I think this is a little cleaner and the code is very simple. I wanted to
> get an opinion on whether this is worth making into a patch.
> Martin Emde
> Tw: @martinemde

Generally this looks really nice, and I can see the use, but it's so
different from everything else that I need to think about it a bit more.
Have you played around w/ any other syntax options that would be more
aligned w/ the "actual.should matcher" format? Something like:

[1,2,3].should yield_on(:each) ???

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-devel/attachments/20091110/452f2fbb/attachment.html>

More information about the rspec-devel mailing list