eproxus / meck

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

Introduce 'stub_all' option #78

Closed horkhe closed 11 years ago

horkhe commented 11 years ago

For those who use mocks in record-then-verify manner (and I am one of them :-)) it would be very convenient to create mocks that have stubs for all exported functions out-of-the-box. This feature introduces such capability. The default stubs allow everything as input arguments and return meck_stub. If in the scope of a test a more specific stub (expectation) is required, then the out-of-the-box stub (expectation) can be overridden by explicit call to meck:expect/3,4.

E.g. If there is a module m1 that exports function f/2 then:

meck:new(m1, [stub_all]),
?assertEquals(meck_stub, m1:f(blah, whatever)).
eproxus commented 11 years ago

Might I suggest a few changes?

horkhe commented 11 years ago

It is a neat idea to allow defining values returned by stubs. I just implemented it in a more general way. Any valid ret_spec() can be specified as a return value of the stub_all option.

eproxus commented 11 years ago

Alternatively we have to expand the stub_all option to {stub_all, ok} first, and then use that in combination with proplists:is_defined(stub_all, Options) to see if we can trust the return value of proplists:get_value(stub_all, Options) or not.

horkhe commented 11 years ago

Fixed this case too.

horkhe commented 11 years ago

I wonder, why my pull request does not have that nice green label from Travis-CI that it is ok to merge...

eproxus commented 11 years ago

Nice work!