Re: [rspec-users] Asserting on a yield

2012-03-17 Thread Zach Dennis
On Sat, Mar 17, 2012 at 7:52 PM, Justin Ko wrote: > > On Mar 17, 2012, at 3:51 PM, Myron Marston wrote: > >> I've been thinking about this a bit ever since Zach Dennis brought up >> the issue on another rspec-expectations ticket [1]. I've come up with >> a proof-of-concept matcher that works prett

Re: [rspec-users] Asserting on a yield

2012-03-17 Thread Justin Ko
On Mar 17, 2012, at 3:51 PM, Myron Marston wrote: > I've been thinking about this a bit ever since Zach Dennis brought up > the issue on another rspec-expectations ticket [1]. I've come up with > a proof-of-concept matcher that works pretty well, I think [2]. > Here's how you use it: > > expect

Re: [rspec-users] Asserting on a yield

2012-03-17 Thread Myron Marston
I've been thinking about this a bit ever since Zach Dennis brought up the issue on another rspec-expectations ticket [1]. I've come up with a proof-of-concept matcher that works pretty well, I think [2]. Here's how you use it: expect { |b| 3.tap(&b) }.to yield_value(3) The argument passed to the

Re: [rspec-users] Asserting on a yield

2012-03-08 Thread Morten Møller Riis
&:self won't work because self isn't an instance method on the object, eg. some_object.self won't work either. If you wan't something cleaner couldn't you use this method in spec_helper.rb ? def block_yield(object, method) object.send(method) { yield if block_given? } end Then: block_yield(t

Re: [rspec-users] Asserting on a yield

2012-03-07 Thread Matt Wynne
On 7 Mar 2012, at 18:26, Zach Dennis wrote: > Matt, > > I have typically done what you are already doing, but I am also > interested in the answer you seek. Another idea might be something > like since #do-stuff would need to be invoked with a block: > > expect(thing, :do_stuff).to_yield val

Re: [rspec-users] Asserting on a yield

2012-03-07 Thread David Chelimsky
On Wed, Mar 7, 2012 at 2:32 PM, Matt Wynne wrote: > > On 7 Mar 2012, at 18:16, David Chelimsky wrote: > > On Wed, Mar 7, 2012 at 11:56 AM, Matt Wynne wrote: > > > On 7 Mar 2012, at 11:39, Morten Møller Riis wrote: > > > On Mar 7, 2012, at 8:22 AM, Matt Wynne wrote: > > > > Hi all, > > > I'm spec'

Re: [rspec-users] Asserting on a yield

2012-03-07 Thread Matt Wynne
On 7 Mar 2012, at 18:16, David Chelimsky wrote: > On Wed, Mar 7, 2012 at 11:56 AM, Matt Wynne wrote: >> >> On 7 Mar 2012, at 11:39, Morten Møller Riis wrote: >> >> 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 sp

Re: [rspec-users] Asserting on a yield

2012-03-07 Thread Zach Dennis
Matt, I have typically done what you are already doing, but I am also interested in the answer you seek. Another idea might be something like since #do-stuff would need to be invoked with a block: expect(thing, :do_stuff).to_yield val Zach On Wed, Mar 7, 2012 at 12:56 PM, Matt Wynne wrote:

Re: [rspec-users] Asserting on a yield

2012-03-07 Thread David Chelimsky
On Wed, Mar 7, 2012 at 11:56 AM, Matt Wynne wrote: > > On 7 Mar 2012, at 11:39, Morten Møller Riis wrote: > > 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 { |valu

Re: [rspec-users] Asserting on a yield

2012-03-07 Thread David Chelimsky
On Wed, Mar 7, 2012 at 11:53 AM, Matt Wynne wrote: > > On 7 Mar 2012, at 15:12, Ken Chien wrote: > > Hi Matt, > On Wed, Mar 7, 2012 at 2: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_s

Re: [rspec-users] Asserting on a yield

2012-03-07 Thread Matt Wynne
On 7 Mar 2012, at 15:12, Ken Chien wrote: > Hi Matt, > On Wed, Mar 7, 2012 at 2: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 == expecte

Re: [rspec-users] Asserting on a yield

2012-03-07 Thread Matt Wynne
On 7 Mar 2012, at 11:39, Morten Møller Riis wrote: > 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 == expec

Re: [rspec-users] Asserting on a yield

2012-03-07 Thread Ken Chien
Hi Matt, On Wed, Mar 7, 2012 at 2: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 wa

Re: [rspec-users] Asserting on a yield

2012-03-07 Thread Morten Møller Riis
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 = valu

[rspec-users] Asserting on a yield

2012-03-06 Thread Matt Wynne
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(expec