I wouldn&#39;t try doing this. You risk getting highly coupled test code. I&#39;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 &lt;
<a href="mailto:jonathan@parkerhill.com">jonathan@parkerhill.com</a>&gt;:</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>&gt;<br>&gt; On Dec 13, 2007, at 2:06 AM, Jarkko Laine wrote:<br>&gt;<br>&gt;&gt;<br>&gt;&gt; On 13.12.2007, at 9.00, Jonathan Linowes wrote:<br>&gt;&gt;<br>&gt;&gt;&gt; is there a way to stub a method that sets an instance variable, so
<br>&gt;&gt;&gt; the stub sets it too?<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; def find_foo<br>&gt;&gt;&gt;&nbsp;&nbsp; @foo = Foo.find(params[:id]<br>&gt;&gt;&gt; end<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; ...<br>&gt;&gt;&gt; controller.stub!
(:find_foo).and_assigns(:foo, &quot;123&quot;)<br>&gt;&gt;<br>&gt;&gt; Why don&#39;t you just stub Foo.find? That way the instance var gets<br>&gt;&gt; assigned automatically.<br>&gt;&gt;<br>&gt;&gt; //jarkko<br>&gt;&gt;<br>
&gt;<br>&gt; Sorry, perhaps I gave too simplistic an example.<br>&gt; My question is what if I want to stub the whole find_foo method<br>&gt; but one of its side effects is it sets @foo<br>&gt; (rather than stub the internals of find_foo)
<br>&gt;<br>&gt;<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>