This is the mockingbird Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 07:05:39 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
mockingbird
Christopher Eames (Chream)
MIT
# Mockingbird
This package provides some useful stubbing and mocking macros for unit testing. Used when specified functions in a test should not be computed but should instead return a provided constant value.
This library was called cl-mock before but is/was NOT the library called "cl-mock" on quicklisp. I have now changed the name.
## Usage
“‘
(in-package :cl-user)
(uiop:define-package :my-project
(:use :closer-common-lisp
:prove
:mockingbird))
(in-package :my-project)
(defun foo (x) x)
(defun bar (x y) (+ x (foo x)))
(with-stubs ((foo 10))
(is (foo 1 2) 10)) ;; –> T
(is (bar 1 2) 2)) ;; –> T Only lexically stubbed!
(with-dynamic-stubs ((foo 10))
(is (foo 1 2) 10)) ;; –> T
(is (bar 1 2) 11)) ;; –> T Dynamically stubbed!
(with-mocks (foo bar)
(is (foo 5) nil) ;; –> T
(is (bar 10) nil)) ;; –> T Args dont need to match!
(with-dynamic-mocks (foo bar)
...)
“‘
The arguments passed to mocked or stubbed functions are also saved.
“‘
(with-stubs ((foo 5))
(foo 4 5)
(call-times-for ’foo) ;; –> 1
(verify-call-times-for ’foo 1) ;; –> T
(nth-mock-args-for 1 ’foo) ;; –> ’(4 5)
(verify-nth-call-args-for 1 ’foo 4 5) ;; –> T
(verify-first-call-args-for ’foo 4 5) ;; –> T
(clear-calls)) ;; –> no-value
“‘
These also work for the dynamic and mocking variants.
——————————————————————-
It is also possible to mock/stub individual methods.
“‘
(with-method-stubs ((foo (x y) ’is-stubbed)
(foo ((x aclass) (y aclass)) ’aclass-stubbed)
...)
“‘
The calls to methods are currently NOT saved so the above verification functions can not be used.
## Installation
Clone this repository and put into asdf load path then
“‘
(ql:quickload :mockingbird)
“‘
To run tests:
“‘
(ql:test-system :mockingbird)
“‘
## Author
* Christopher Eames (Chream) (chream@gmx.com)
## Copyright
Copyright (c) 2016 Christopher Eames (Chream) (chream@gmx.com)
0.1
mockingbird/src/all
(system).
mockingbird/src/all
Christopher Eames (Chream)
MIT
closer-mop
(system).
mockingbird/src/functions
(system).
mockingbird/src/methods
(system).
mockingbird/src/functions
Christopher Eames (Chream)
MIT
closer-mop
(system).
fare-utils
(system).
alexandria
(system).
trivial-arguments
(system).
mockingbird/src/methods
Christopher Eames (Chream)
MIT
closer-mop
(system).
fare-utils
(system).
alexandria
(system).
closer-mop
(system).
mockingbird/src/functions
(system).
Files are sorted by type and then listed depth-first from the systems components trees.
mockingbird/mockingbird.asd
mockingbird/src/all/file-type.lisp
mockingbird/src/functions/file-type.lisp
mockingbird/src/methods/file-type.lisp
mockingbird/mockingbird.asd
mockingbird
(system).
mockingbird/src/all/file-type.lisp
mockingbird/src/all
(system).
mockingbird/src/functions/file-type.lisp
mockingbird/src/functions
(system).
*mock-calls*
(special variable).
call-times-for
(function).
clear-calls
(function).
nth-mock-args-for
(function).
undefined-stub-function-error
(function).
verify-call-times-for
(function).
verify-first-call-args-for
(macro).
verify-nth-call-args-for
(function).
with-dynamic-mocks
(macro).
with-dynamic-stubs
(macro).
with-mocks
(macro).
with-stubs
(macro).
defined-fns-bound-p
(function).
flet-spec
(function).
fn-names-from
(function).
mock-calls-for
(function).
mock-calls-spec-for
(function).
mock-fn-registered-p
(function).
rebind-original-fn-bindings-spec
(function).
register-mock-call-for
(function).
replace-fn-bindings-spec
(function).
returns-from
(function).
stub-fns-from
(function).
undefined-stub-function
(condition).
mockingbird/src/methods/file-type.lisp
mockingbird/src/methods
(system).
add-methods-for
(function).
applicable-methods-metaobjects-from
(function).
generic-function-method-combination-options
(generic function).
generic-function-method-combination-type-name
(generic function).
gf-metaobjects-from
(function).
method-combination-options
(method).
method-combination-type-name
(generic function).
method-metaobjects-from
(function).
method-spec-from
(function).
remove-methods-for
(function).
specializers/list-from
(function).
with-method-stubs
(macro).
filter-applicable-methods
(generic function).
method-combination-type-options
(generic function).
undefined-stub-error-specializers
(reader method).
undefined-stub-method
(condition).
undefined-stub-method-error
(function).
Packages are listed by definition order.
mockingbird/src/all
mockingbird
mb
closer-common-lisp
.
mockingbird/src/functions
.
mockingbird/src/methods
.
mockingbird/src/functions
mb.functions
alexandria
.
closer-common-lisp
.
fare-utils
.
uiop/driver
.
*mock-calls*
(special variable).
call-times-for
(function).
clear-calls
(function).
nth-mock-args-for
(function).
undefined-stub-function-error
(function).
verify-call-times-for
(function).
verify-first-call-args-for
(macro).
verify-nth-call-args-for
(function).
with-dynamic-mocks
(macro).
with-dynamic-stubs
(macro).
with-mocks
(macro).
with-stubs
(macro).
defined-fns-bound-p
(function).
flet-spec
(function).
fn-names-from
(function).
mock-calls-for
(function).
mock-calls-spec-for
(function).
mock-fn-registered-p
(function).
rebind-original-fn-bindings-spec
(function).
register-mock-call-for
(function).
replace-fn-bindings-spec
(function).
returns-from
(function).
stub-fns-from
(function).
undefined-stub-function
(condition).
undefined-stub-method
(condition).
mockingbird/src/methods
alexandria
.
closer-common-lisp
.
fare-utils
.
uiop/driver
.
add-methods-for
(function).
applicable-methods-metaobjects-from
(function).
generic-function-method-combination-options
(generic function).
generic-function-method-combination-type-name
(generic function).
gf-metaobjects-from
(function).
method-combination-options
(generic function).
method-combination-type-name
(generic function).
method-metaobjects-from
(function).
method-spec-from
(function).
remove-methods-for
(function).
specializers/list-from
(function).
with-method-stubs
(macro).
filter-applicable-methods
(generic function).
method-combination-type-options
(generic function).
specializers
(slot).
undefined-stub-error-specializers
(generic reader).
undefined-stub-method-error
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
The mock macro. Lexically binds a new mock function which will return nil. Calls are counted and the arguments are saved in the dynamic variable *mock-calls*.
The stub macro. Lexically binds a new stub function in place and returns a constant supplied value. Calls are counted and the arguments are saved in the dynamic variable *mock-calls*.
The error function for undefined-stub-function.
generic-function
)) ¶generic-function
)) ¶method-combination
)) ¶method-combination
)) ¶Accessor function for the special *mock-calls* variable. Returns the value associated with the function.
Accessor function for the special *mock-calls* variable. Returns the full spec.
The error function for undefined-stub-function.
undefined-stub-method
)) ¶Error:
undefined-function
.
Error:
undefined-function
.
:specializers
This slot is read-only.
Jump to: | A C D F G M N R S U V W |
---|
Jump to: | A C D F G M N R S U V W |
---|
Jump to: | *
S |
---|
Index Entry | Section | ||
---|---|---|---|
| |||
* | |||
*mock-calls* : | Public special variables | ||
| |||
S | |||
Slot, specializers : | Private conditions | ||
Special Variable, *mock-calls* : | Public special variables | ||
specializers : | Private conditions | ||
|
Jump to: | *
S |
---|
Jump to: | C F M P S U |
---|
Jump to: | C F M P S U |
---|