Testing with blocks and yield_with_args

281 views
Skip to first unread message

Nicholas Wieland

unread,
Feb 23, 2015, 8:54:18 AM2/23/15
to rs...@googlegroups.com
Hi I'm trying to test the return the value returned by a method that accepts a block, that should yield a double.


I don't know what I'm doing wrong, most probably I don't understand how to use the matched. Can someone help me out?

  ngw

Myron Marston

unread,
Feb 23, 2015, 3:16:58 PM2/23/15
to rs...@googlegroups.com
 `yield_with_args` expects arguments, which specify what arguments you expect to be yielded.  You passed `yield_with_args` no args.  I think you want `yield_with_args(post)`.

That said, you pasted only your code, and not the output RSpec is giving you, so I'm not quite sure what isn't working how you expect.  If there's more to it than that, please post the RSpec failure you're getting.

HTH,
Myron 

Nicholas Wieland

unread,
Feb 24, 2015, 9:40:23 AM2/24/15
to rs...@googlegroups.com
Hi, I changed my spec  but still having problems, I'm not able to stub an array-like object ... Thanks for your help!


  ngw

Aaron Kromer

unread,
Feb 24, 2015, 11:54:03 AM2/24/15
to rs...@googlegroups.com

In Ruby each does not necessarily return a meaningful value (it could be nil or self for the object). You are stubbing a return value but each is used to yield to a block; which the stub does not do. Is this object actually an array? I’m a bit confused by it’s contract given your use of each and next with it.

In this situation, I generally would just suggest stubbing an array like object, I would say to just provide an array.


--
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 rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/9bae3a32-c918-430e-a108-33468455e439%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Kromer

unread,
Feb 24, 2015, 11:55:47 AM2/24/15
to rs...@googlegroups.com

*I would generally not suggest stubbing an array like object...

*
Reply all
Reply to author
Forward
0 new messages