About bytecurry.mocks:

Package to provide tools to mock functions in common lisp unit tests.

Provides WITH-MOCKED-FUNCTIONS, which acts like FLET or LABELS, but shadows functions in the global scope, so that the function bindings are available outside of thelexical scope of the body. See docstring for more information.

Other macros in bytecurry.mocks

Macro with-added-methods (bindings &body body)
Details:
Execute BODY with some extra methods.

This works similarly to WITH-MOCKED-FUNCTIONS. But defines methods instead of functions. The bindings should look like DEFMETHOD definitions without the defmethod symbol.

One particularly useful scenario is to mock up an instance of a class by using eql specializers for a local variable.

For now, it only supports adding new methods, not replacing existing methods, since it doesn't restored the previous method. (mostly because I don't know a good way to extract the specifiers from the definition form.)

Macro with-mocked-functions (bindings &body body)
Details:
Execute BODY with some functions mocked up.

BINDINGS is a list of function bindings, similar to those in FLET or LABELS. Before executing BODY, the bindings are used to replace the definitions of functions, and after BODY has finished, the original function definitions are restored.

You can use this macro to mock funtions for unit tests. For example, if function A calls function B, you can replace the definition of B while testing A, to isolate the test on just the behavior of A.

There are two things to note when using this macro: 1. You can't mock functions in a locked package (such as CL) 2. The compiler may inline function calls, in which case changing the definition will have no effect.

Index of exported symbols

bytecurry.mocks:with-added-methods, macro
bytecurry.mocks:with-mocked-functions, macro