Remi Gagnon
2009-Feb-08 12:48 UTC
[rspec-users] How to return a value passed by ref to a method
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090208/4e00e9c2/attachment.html>
David Chelimsky
2009-Feb-08 15:02 UTC
[rspec-users] How to return a value passed by ref to a method
On Sun, Feb 8, 2009 at 6:48 AM, Remi Gagnon <rem.gagnon at 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?> > R?mi > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Remi Gagnon
2009-Feb-08 15:26 UTC
[rspec-users] How to return a value passed by ref to a method
Hello, This is a question from one of my teammate, I''ll revalidate tomorrow with him what is his issue. Thank you R?mi On Sun, Feb 8, 2009 at 10:02 AM, David Chelimsky <dchelimsky at gmail.com>wrote:> On Sun, Feb 8, 2009 at 6:48 AM, Remi Gagnon <rem.gagnon at 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? > > > > > R?mi > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > 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/20090208/04728e5a/attachment-0001.html>
Scott Taylor
2009-Feb-08 20:21 UTC
[rspec-users] How to return a value passed by ref to a method
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