[rspec-users] unexpected should_receive behaviour

Ben Lovell benjamin.lovell at gmail.com
Tue Oct 9 14:11:24 UTC 2012


On 9 October 2012 14:46, enrico stano <enricostn at gmail.com> wrote:

> yes, it's CanCan fault! ;)
>
> any chance to check something like that (pseudo code) ?
>
> User.should_receive(:find).with("1").called_by(User.authorize!)
> User.should_receive(:find).with("1").called_by(controller)
>
> just to check exactly what's happening
>
> thank you!
>
>
You can set the number of times an expectation should be met or the order
in which they're executed:

https://www.relishapp.com/rspec/rspec-mocks/docs/message-expectations/receive-counts

Regards,
Ben


>
> 2012/10/9 Andy Lindeman <alindeman at gmail.com>:
> > On Tue, Oct 9, 2012 at 8:56 AM, enrico stano <enricostn at gmail.com>
> wrote:
> >> Hi Ben,
> >>
> >> you could find more info browsing this Gist
> >> https://gist.github.com/3848429#file_user_controller_spec.rb
> >>
> >> I've added it to my StackOverflow question too.
> >>
> >> Thank you for your time!
> >
> > It's likely that cancan is calling User.find because of
> > load_and_authorize_resource
> >
> > That's likely why you see it being called twice when the stub is removed.
> >
> > --
> > Andy Lindeman
> > http://www.andylindeman.com/
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
>
>
>
> --
> · Enrico Stano
> ·
> · twitter @enricostano
> · skype ocirneonats
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20121009/3e6151e9/attachment.html>


More information about the rspec-users mailing list