Skip to content

Instantly share code, notes, and snippets.

@mbbx6spp
Created March 23, 2011 14:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbbx6spp/883124 to your computer and use it in GitHub Desktop.
Save mbbx6spp/883124 to your computer and use it in GitHub Desktop.
Notes on using Meck API (a mocking library in Erlang) which are not well documented
% Will create a fully mocked version of existing_module until caller crashes
meck:new(ExistingModule).
% Will create a fully mocked version of existing_module even after caller crashes
meck:new(ExistingModule, [nolink]).
% Will allow you to overload existing module, keeping old functions around
meck:new(ExistingModule, [passthrough]).
% Unload mocks and revert to real module implementation
meck:unload(ExistingModule).
% Remove functions from the mock module
meck:delete(WhateverMockedModule, SomeFun, Arity).
% Get list of all function calls made to the module (in order).
History = meck:history(MockedModule).
% History will look _similar_ to an Erlang trace but with {{M, F, A}, Return} format
% e.g. where MockedModule = my_mod
% [
% {{my_mod, print, []}, ok},
% {{my_mod, sum, [1,2,3]}, 6},
% {{my_mod, copy_file, ["non_existing_file", "other_file_name"]}, error, enoent, Stack}
% ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment