eproxus/meck — pull request #89 by horkhe (2012-11-09 11:57:22+00:00)
Title: Introduce matchers in expectations and more:

This pull request makes the following syntax possible:

%% When
meck:expect(Mod, f, [{[1, meck:is(fun(X) -> X == 1 end)], a},
{[1, meck:is(hamcrest_matchers:less_than(3))], b},
{['_', '_'], c}]),
%% Then
?assertEqual(a, Mod:f(1, 1)),
?assertEqual(b, Mod:f(1, 2)),
?assertEqual(c, Mod:f(2, 2)).

As you can see meck:is/1 can create a matcher from any single argument function or a hamcrest matcher. Matchers can be used instead of any expected argument.

Besides matchers the changes also introduced two new ret_spec() kinds that are meck:passthrough/0 and meck:func/1 that make the following possible:

%% When
meck:expect(meck_test_module, c, [{[1, 2], meck:passthrough()},
{['_', '_'], meck:func(fun(A, B) -> {B, A} end)}]),
%% Then
?assertEqual({1, 2}, meck_test_module:c(1, 2)),
?assertEqual({3, 1}, meck_test_module:c(1, 3)),

That comes pretty handy given that you can specify them within meck:seq/1 and meck:loop/1

Besides all ret_spec() aware code was moved to a module of the same name.