Ooops, I mean still getting
Mock 'Coupon_1011' received unexpected message :user= with (#<User:0x22087ba
@name="User_1010">)



On Jan 23, 2008 11:57 AM, Corey Haines <[EMAIL PROTECTED]> wrote:

> Nope, that still didn't work.
> Still getting
>     @coupon.stub!(:user=).with(@current_user)
>
> Here's my spec and code using your recommended way:
>
> spec - http://pastie.caboo.se/142451
> code - http://pastie.caboo.se/142452
>
> If I add back
>     @coupon.stub!(:user=).with(@current_user)
>
> they pass.
>
> 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.
>
> -Corey
>
>
> On Jan 23, 2008 11:50 AM, Jarkko Laine <[EMAIL PROTECTED]> wrote:
>
> > On 23.1.2008, at 18.02, Corey Haines wrote:
> >
> > > I get the unexpected message :user= failure.
> > >
> > > When you set up the mock with the initial parameters, wouldn't those
> > > be stubbing: @ coupon.stub!(:user).and_return(@current_user)
> > >
> >
> > You can do it like this:
> >
> > @coupon = mock_model(Coupon, :user= => nil, :user =>
> > @current_user, :save => true)
> >
> > That stubs both user= and user. I often create reusable "mock
> > factories" in spec_helper.rb that take care of the normal methods for
> > AR objects:
> >
> > def mock_coupon(opts = {})
> >   mock_model(Coupon, {:user= => nil, :user => mock_user, :save =>
> > true}.merge(opts))
> > end
> >
> > Often I also stub the errors method there because it's called pretty
> > often in controllers and views.
> >
> > //jarkko
> >
> > --
> > Jarkko Laine
> > http://jlaine.net
> > http://dotherightthing.com
> > http://www.railsecommerce.com
> > http://odesign.fi
> >
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users@rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
>
>
>
> --
>
> 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
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to