Forum: Ruby Mocha: expects any number of time

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fernando P. (Guest)
on 2009-04-17 20:05
Hi,

How to create an assertion that only checks that a given method is
invoked at least once.

In my Rails app I wanted to mock current_user, but I don't care how many
times it gets called, but I want to make sure it is called, so:

@controller.expects(:current_user).returns(@user)

doesn't work, because for instance it tells it was already invoked once.


Thanks.
Fernando P. (Guest)
on 2009-04-17 20:11
Ok I found it:

expects(:method).at_least_once
Ben L. (Guest)
on 2009-04-17 20:29
(Received via mailing list)
On Fri, Apr 17, 2009 at 5:05 PM, Fernando P.
<removed_email_address@domain.invalid>wrote:

> Hi,
>
> How to create an assertion that only checks that a given method is
> invoked at least once.
>
> @controller.expects(:current_user).returns(@user)
>
>
>
How about:

@controller.expects(:current_user).at_least_once.returns(@user)

Ben
This topic is locked and can not be replied to.