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 <<a href="mailto:dchelimsky@gmail.com">
dchelimsky@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;"><div class="Ih2E3d">On Jan 23, 2008 8:41 AM, Corey Haines <
<a href="mailto:coreyhaines@gmail.com">coreyhaines@gmail.com</a>> wrote:<br></div><div><div></div><div class="Wj3C7c">> All,<br>><br>> I'm missing something simple, I think. I am writing a spec to say that my
<br>> CouponController should create a new coupon from the form parameters, then<br>> 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>><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<br>> parameters and save" do<br>> post<br>> '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<br>> @name="User_1009">)<br><br><br>
</div></div>That'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>><br>> I'm sure that I'm missing something very simple, but I've been staring at it<br>> for too long.<br>><br>> (also, if anyone has commented on my style, please feel free to mention it,
<br>> 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<br>> totally sure how to get the versions of the plugins
<br>><br>><br>> Thanks.<br>> -Corey<br>><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
<br></div>> _______________________________________________<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>><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's Premiere source of information about Corey Haines