Nope, that still didn&#39;t work. <br>Still getting<br>&nbsp;&nbsp;&nbsp; @coupon.stub!(:user=).with(@current_user)<br>&nbsp;<br>Here&#39;s my spec and code using your recommended way:<br><br>spec - <a href="http://pastie.caboo.se/142451">http://pastie.caboo.se/142451
</a><br>code - <a href="http://pastie.caboo.se/142452">http://pastie.caboo.se/142452</a><br><br>If I add back<br>&nbsp;&nbsp;&nbsp; @coupon.stub!(:user=).with(@current_user)<br><br>they pass.<br><br>It seems as though the understanding is that setting up your mock with the options (:user =&gt; @current_user) should set stubs for both get and set, but it doesn&#39;t. I think it just sets up the stub for the get.
<br><br>-Corey<br><br><div class="gmail_quote">On Jan 23, 2008 11:50 AM, Jarkko Laine &lt;<a href="mailto:jarkko@jlaine.net">jarkko@jlaine.net</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On 23.1.2008, at 18.02, Corey Haines wrote:<br><br>&gt; I get the unexpected message :user= failure.<br>&gt;<br>&gt; When you set up the mock with the initial parameters, wouldn&#39;t those<br>&gt; be stubbing: @
coupon.stub!(:user).and_return(@current_user)<br>&gt;<br><br></div>You can do it like this:<br><br>@coupon = mock_model(Coupon, :user= =&gt; nil, :user =&gt;<br>@current_user, :save =&gt; true)<br><br>That stubs both user= and user. I often create reusable &quot;mock
<br>factories&quot; in spec_helper.rb that take care of the normal methods for<br>AR objects:<br><br>def mock_coupon(opts = {})<br> &nbsp; mock_model(Coupon, {:user= =&gt; nil, :user =&gt; mock_user, :save =&gt;<br>true}.merge(opts))
<br>end<br><br>Often I also stub the errors method there because it&#39;s called pretty<br>often in controllers and views.<br><br>//jarkko<br><font color="#888888"><br>--<br>Jarkko Laine<br><a href="http://jlaine.net" target="_blank">
http://jlaine.net</a><br><a href="http://dotherightthing.com" target="_blank">http://dotherightthing.com</a><br><a href="http://www.railsecommerce.com" target="_blank">http://www.railsecommerce.com</a><br><a href="http://odesign.fi" target="_blank">
http://odesign.fi</a><br></font><div><div></div><div class="Wj3C7c"><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" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.coreyhaines.com">
http://www.coreyhaines.com</a><br>The Internet&#39;s Premiere source of information about Corey Haines