Of course. Thanks, David! I still am getting used to user=, rather than just user. Thanks again.<br><br>-Corey<br><br><div class="gmail_quote">On Jan 23, 2008 9:46 AM, David Chelimsky &lt;<a href="mailto:dchelimsky@gmail.com">
dchelimsky@gmail.com</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 Jan 23, 2008 8:41 AM, Corey Haines &lt;
<a href="mailto:coreyhaines@gmail.com">coreyhaines@gmail.com</a>&gt; wrote:<br></div><div><div></div><div class="Wj3C7c">&gt; All,<br>&gt;<br>&gt; I&#39;m missing something simple, I think. I am writing a spec to say that my
<br>&gt; CouponController should create a new coupon from the form parameters, then<br>&gt; set the current user. Here&#39;s the spec:<br>&gt;<br>&gt; describe CouponController, &quot;When posting to save_coupon&quot; do<br>
&gt;<br>&gt; &nbsp; before(:each) do<br>&gt; &nbsp; &nbsp; @expectedName = &quot;pepper&#39;s&quot;<br>&gt; &nbsp; &nbsp; @expectedAmount = 5<br>&gt;<br>&gt; &nbsp; &nbsp; coupon = mock_model Coupon<br>&gt; &nbsp; &nbsp; current_user = mock_model User<br>&gt; &nbsp; &nbsp; controller.stub!
(:current_user).and_return(current_user)<br>&gt;<br>&gt; Coupon.should_receive(:new).with({&quot;name&quot;=&gt;@expectedName,&quot;amount&quot;=&gt;@expectedAmount}).and_return(coupon)<br>&gt; &nbsp; &nbsp; coupon.should_receive(:user).with(current_user)
<br>&gt; &nbsp; &nbsp; coupon.should_receive(:save)<br>&gt; &nbsp; end<br>&gt;<br>&gt; &nbsp; it &quot;should tell the Coupon model to create a new coupon with the given<br>&gt; parameters and save&quot; do<br>&gt; &nbsp; &nbsp; post<br>&gt; &#39;save_coupon&#39;,{:coupon=&gt;{:name=&gt;@expectedName,:amount=&gt;@expectedAmount}}
<br>&gt; &nbsp; end<br>&gt;<br>&gt; Here&#39;s the controller method:<br>&gt;<br>&gt; &nbsp; def save_coupon<br>&gt; &nbsp; &nbsp; coupon = Coupon.new(params[:coupon])<br>&gt; &nbsp; &nbsp; coupon.user = current_user<br>&gt; &nbsp; &nbsp; coupon.save<br>&gt; &nbsp; &nbsp; redirect_to_index &quot;Coupon Added!&quot;
<br>&gt; &nbsp; end<br>&gt;<br>&gt; And, I get the following failure:<br>&gt;<br>&gt; Mock &#39;Coupon_1008&#39; received unexpected message :user= with (#&lt;User:0x221a3e8<br>&gt; @name=&quot;User_1009&quot;&gt;)<br><br><br>
</div></div>That&#39;s from this line in save_coupon:<br><br>coupon.user = current_user<br><br>Just need to stub that:<br><br>coupon.stub!(:user=)<br><br>Or you could expect it:<br><div class="Ih2E3d"><br>coupon.should_receive
(:user=).with(current_user)<br><br></div>Cheers,<br>David<br><div class="Ih2E3d"><br>&gt;<br>&gt; I&#39;m sure that I&#39;m missing something very simple, but I&#39;ve been staring at it<br>&gt; for too long.<br>&gt;<br>&gt; (also, if anyone has commented on my style, please feel free to mention it,
<br>&gt; as I&#39;m still adjusting my mind to rspec)<br>&gt;<br>&gt; Oh, versions, I almost forgot:<br>&gt; rails 2.0.2<br>&gt; rspec(_on_rails) plugins just updated from current a couple days ago, not<br>&gt; totally sure how to get the versions of the plugins
<br>&gt;<br>&gt;<br>&gt; Thanks.<br>&gt; -Corey<br>&gt;<br>&gt; --<br>&gt; <a href="http://www.coreyhaines.com" target="_blank">http://www.coreyhaines.com</a><br>&gt; The Internet&#39;s Premiere source of information about Corey Haines
<br></div>&gt; _______________________________________________<br>&gt; rspec-users mailing list<br>&gt; <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>&gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br>&gt;<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></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