I wouldn't try doing this. You risk getting highly coupled test code. I'd rather use a little helper method that does this for you.<br><br>Stefan<br><br><div><span class="gmail_quote">2007/12/13, Jonathan Linowes <
<a href="mailto:jonathan@parkerhill.com">jonathan@parkerhill.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>On Dec 13, 2007, at 2:47 AM, Jonathan Linowes wrote:
<br><br>><br>> On Dec 13, 2007, at 2:06 AM, Jarkko Laine wrote:<br>><br>>><br>>> On 13.12.2007, at 9.00, Jonathan Linowes wrote:<br>>><br>>>> is there a way to stub a method that sets an instance variable, so
<br>>>> the stub sets it too?<br>>>><br>>>> def find_foo<br>>>> @foo = Foo.find(params[:id]<br>>>> end<br>>>><br>>>><br>>>> ...<br>>>> controller.stub!
(:find_foo).and_assigns(:foo, "123")<br>>><br>>> Why don't you just stub Foo.find? That way the instance var gets<br>>> assigned automatically.<br>>><br>>> //jarkko<br>>><br>
><br>> Sorry, perhaps I gave too simplistic an example.<br>> My question is what if I want to stub the whole find_foo method<br>> but one of its side effects is it sets @foo<br>> (rather than stub the internals of find_foo)
<br>><br>><br>... and @foo is used by the method that i am testing<br><br>_______________________________________________<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org
</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></div><br><br clear="all"><br>-- <br>Bekk Open Source<br><a href="http://boss.bekk.no">
http://boss.bekk.no</a>