Nope, that still didn't work. <br>Still getting<br> @coupon.stub!(:user=).with(@current_user)<br> <br>Here'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> @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 => @current_user) should set stubs for both get and set, but it doesn'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 <<a href="mailto:jarkko@jlaine.net">jarkko@jlaine.net</a>> 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>> I get the unexpected message :user= failure.<br>><br>> When you set up the mock with the initial parameters, wouldn't those<br>> be stubbing: @
coupon.stub!(:user).and_return(@current_user)<br>><br><br></div>You can do it like this:<br><br>@coupon = mock_model(Coupon, :user= => nil, :user =><br>@current_user, :save => true)<br><br>That stubs both user= and user. I often create reusable "mock
<br>factories" in spec_helper.rb that take care of the normal methods for<br>AR objects:<br><br>def mock_coupon(opts = {})<br> mock_model(Coupon, {:user= => nil, :user => mock_user, :save =><br>true}.merge(opts))
<br>end<br><br>Often I also stub the errors method there because it'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's Premiere source of information about Corey Haines