Created
March 23, 2011 14:00
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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