eproxus / meck

A mocking library for Erlang
http://eproxus.github.io/meck
Apache License 2.0
811 stars 231 forks source link

Wait for a number of function calls #81

Closed horkhe closed 11 years ago

horkhe commented 11 years ago

It would be great if we could wait for a particular function of a mocked module to be called a particular number of times with particular parameters. E.g.

meck:new(some_mod, [passthrough]),
....
meck:wait_4_call(3, {some_mod, f1, [blah, '_', 10]}, 10000).

where

-spec wait_4_call(CalledTimes :: non_neg_integer(),
                  {module(), func(), args_pattern()},
                  Timeout :: erlang:timeout()) ->
        ok.

The wait_4_call should fail if the call pattern, that we are waiting upon, is not met within the time specified by Timeout.

I personally need this capability to use in my functional tests to get rid of ugly timer:sleep/1.

eproxus commented 11 years ago

This is a really good idea!

Maybe we could call it wait only? (Also, timeout should be optional)

horkhe commented 11 years ago

I will start working on it as soon as finish splitting of the meck module.