Forum: RSpec How to return a value passed by ref to a method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
161c0829c95d759f4dc0e0b71f712109?d=identicon&s=25 Rémi Gagnon (rgagnon)
on 2009-02-08 14:01
(Received via mailing list)
Hi,

I have a recursive method and I want to mock a var passed by ref.
Object.should_receive(:my_method).and_return"by_ref"(@value)

Something like that.

Any idea?

Rémi
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-02-08 16:16
(Received via mailing list)
On Sun, Feb 8, 2009 at 6:48 AM, Remi Gagnon <rem.gagnon@gmail.com>
wrote:
> Hi,
>
> I have a recursive method and I want to mock a var passed by ref.
> Object.should_receive(:my_method).and_return"by_ref"(@value)
>
> Something like that.
>
> Any idea?

AFAIK, Ruby has no language construct for "by_ref/by_val," so I'm not
sure what you're getting at here. Are you saying that you want the
method to return the value of an @value instance variable in the
object?
161c0829c95d759f4dc0e0b71f712109?d=identicon&s=25 Rémi Gagnon (rgagnon)
on 2009-02-08 16:49
(Received via mailing list)
Hello,

This is a question from one of my teammate, I'll revalidate tomorrow
with
him what is his issue.

Thank you

Rémi
369b9fd2a0d9e7cdbc60907a2a056ad9?d=identicon&s=25 Scott Taylor (Guest)
on 2009-02-08 23:43
(Received via mailing list)
Remi Gagnon wrote:
> Hi,
>
> I have a recursive method and I want to mock a var passed by ref.
> Object.should_receive(:my_method).and_return"by_ref"(@value)
>
Often a way to spec a recursive function is to alias it, and have the
recursive call call the alias.  So if you want to check the recursion,
you could do something like this (in a lispy-type ruby):

http://gist.github.com/60491

Scott
This topic is locked and can not be replied to.