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

Martin Emde martin.emde at gmail.com
Sun Nov 29 15:11:16 EST 2009

On Tue, Nov 10, 2009 at 5:00 PM, David Chelimsky <dchelimsky at gmail.com>wrote:

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

This does follow rspec syntax more closely... Let's run through a few use
cases I can imagine.

helper.should yield_on(:admin_only)
# helper.admin_only &should_yield

[1,2,3].should yield_on(:each).each_of(1,2,3)
# [1,2,3].each &should_yield_each(1,2,3)

h = { :a => 1, :b => 2 }
h.should yield_on(:each).each_of(*h.to_a)
h.each &should_yield_each(*h.to_a)

helper.should yield_on(:link_to_function, "link
#  helper.link_to_function "link text",

I think both are pretty clear until the last example when this part in my
format:  *"link text", &should_yield(...)*   starts to confuse what's going
on exactly. It very clearly breaks from rspec syntax in that example.

helper.link_to_functio("link text", &assert_yielded_block)

That actually makes a bit more sense since the intention is clear. I'm
passing a block that asserts that it will be yielded. However, this isn't
rspec at all written like that.

The yield_on format seems to specify "When I call this method on the
receiver, I expect it to yield." This is very similar to user.should
be_an_admin in that the actual method call is not being called on the
receiver but passed into the matcher.

Is this something we'd like to add to rspec? If so, I'll work out a patch.

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

More information about the rspec-devel mailing list