Oh, and one follow-up, the app works how I expect it to work if I run through the browser.<br><br><div class="gmail_quote">On Jan 23, 2008 9:41 AM, Corey Haines <<a href="mailto:coreyhaines@gmail.com">coreyhaines@gmail.com
</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;">All,<br><br>I'm missing something simple, I think. I am writing a spec to say that my CouponController should create a new coupon from the form parameters, then set the current user. Here's the spec:
<br><br>describe CouponController, "When posting to save_coupon" do
<br><br> before(:each) do<br> @expectedName = "pepper's"<br> @expectedAmount = 5<br><br> coupon = mock_model Coupon<br> current_user = mock_model User<br> controller.stub!(:current_user).and_return(current_user)
<br> Coupon.should_receive(:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon)<br> coupon.should_receive(:user).with(current_user)<br> coupon.should_receive
(:save)
<br> end<br><br> it "should tell the Coupon model to create a new coupon with the given parameters and save" do<br> post 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}}
<br> end<br><br>Here's the controller method:<br><br> def save_coupon<br> coupon = Coupon.new(params[:coupon])<br> coupon.user = current_user<br> coupon.save<br> redirect_to_index "Coupon Added!"
<br> end<br><br>And, I get the following failure:<br><br>Mock 'Coupon_1008' received unexpected message :user= with (#<User:0x221a3e8 @name="User_1009">)<br><br>I'm sure that I'm missing something very simple, but I've been staring at it for too long.
<br><br>(also, if anyone has commented on my style, please feel free to mention it, as I'm still adjusting my mind to rspec)<br><br>Oh, versions, I almost forgot:<br>rails 2.0.2<br>rspec(_on_rails) plugins just updated from current a couple days ago, not totally sure how to get the versions of the plugins
<br><br><br>Thanks.<br>-Corey<br clear="all"><font color="#888888"><br>-- <br><a href="http://www.coreyhaines.com" target="_blank">http://www.coreyhaines.com</a><br>The Internet's Premiere source of information about Corey Haines
</font></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