Stub and setting expectation on method which takes ruby shorthand block as parameter

31 views
Skip to first unread message

siva

unread,
Feb 25, 2014, 11:47:55 PM2/25/14
to rs...@googlegroups.com

  Hi Guys

     I have query as `Enquiry.all.group_by(&:assigned_to)`. How can I stub and set expectation on `group_by` method?


    Thanks in advance.

Xavier Shay

unread,
Feb 26, 2014, 1:16:59 AM2/26/14
to rs...@googlegroups.com

On 25/02/14 8:47 PM, siva wrote:
>
> Hi Guys
>
> I have query as `Enquiry.all.group_by(&:assigned_to)`. How can I
> stub and set expectation on `group_by` method?
specific answer: use stub_chain
meta-answer: don't do that, refactor your code. 2 reasons: you're
mocking an object you don't control, and you're violating law of demeter.

>
>
> Thanks in advance.
> --
> 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/f663e473-7adc-49e5-ae9f-aa00894d3fe8%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages