[rspec-users] Not seeing the failure

Corey Haines coreyhaines at gmail.com
Wed Jan 23 09:42:10 EST 2008


Oh, and one follow-up, the app works how I expect it to work if I run
through the browser.

On Jan 23, 2008 9:41 AM, Corey Haines <coreyhaines at gmail.com> wrote:

> All,
>
> 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:
>
> describe CouponController, "When posting to save_coupon" do
>
>   before(:each) do
>     @expectedName = "pepper's"
>     @expectedAmount = 5
>
>     coupon = mock_model Coupon
>     current_user = mock_model User
>     controller.stub!(:current_user).and_return(current_user)
>     Coupon.should_receive
> (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon)
>     coupon.should_receive(:user).with(current_user)
>     coupon.should_receive(:save)
>   end
>
>   it "should tell the Coupon model to create a new coupon with the given
> parameters and save" do
>     post
> 'save_coupon',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}}
>   end
>
> Here's the controller method:
>
>   def save_coupon
>     coupon = Coupon.new(params[:coupon])
>     coupon.user = current_user
>     coupon.save
>     redirect_to_index "Coupon Added!"
>   end
>
> And, I get the following failure:
>
> Mock 'Coupon_1008' received unexpected message :user= with
> (#<User:0x221a3e8 @name="User_1009">)
>
> I'm sure that I'm missing something very simple, but I've been staring at
> it for too long.
>
> (also, if anyone has commented on my style, please feel free to mention
> it, as I'm still adjusting my mind to rspec)
>
> Oh, versions, I almost forgot:
> rails 2.0.2
> rspec(_on_rails) plugins just updated from current a couple days ago, not
> totally sure how to get the versions of the plugins
>
>
> Thanks.
> -Corey
>
> --
> http://www.coreyhaines.com
> The Internet's Premiere source of information about Corey Haines




-- 
http://www.coreyhaines.com
The Internet's Premiere source of information about Corey Haines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080123/a97c0340/attachment.html 


More information about the rspec-users mailing list