[rspec-users] Asserting on a yield

Morten Møller Riis mortenmoellerriis at gmail.com
Wed Mar 7 11:39:13 UTC 2012


How about this?

thing.do_stuff(&:to_s).should == expected


Best regards
Morten Møller Riis



On Mar 7, 2012, at 8:22 AM, Matt Wynne wrote:

> Hi all,
> 
> I'm spec'ing a method that yields a value. Right now, I spec it like this:
> 
>     result = nil
>     thing.do_stuff { |value| result = value }
>     result.should == expected
> 
> This feels like too much ceremony. What I want to do is something more this:
> 
>    thing.do_stuff.should yield_value(expected)
> 
> Is there anything built into RSpec to let me do this? If not, how do other people test yields?
> 
> cheers,
> Matt
> 
> --
> Freelance programmer & coach
> Author, http://pragprog.com/book/hwcuc/the-cucumber-book
> Founder, http://www.relishapp.com/
> Twitter, https://twitter.com/mattwynne
> 
> 
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120307/ddfb2f84/attachment.html>


More information about the rspec-users mailing list