The mockingbird Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The mockingbird Reference Manual

This is the mockingbird Reference Manual, version 0.1, generated automatically by Declt version 2.3 "Robert April" on Tue Feb 20 09:05:25 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

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

Copyright

Copyright (c) 2016 Christopher Eames (Chream) (chream@gmx.com)


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Next: , Previous: , Up: Systems   [Contents][Index]

2.1 mockingbird

Author

Christopher Eames (Chream)

License

MIT

Description
Long Description

# 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)

Version

0.1

Dependency

mockingbird/src/all (system)

Source

mockingbird.asd (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.2 mockingbird/src/all

Dependencies
Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.3 mockingbird/src/methods

Dependencies
Component

lisp.lisp (file)


Previous: , Up: Systems   [Contents][Index]

2.4 mockingbird/src/functions

Dependencies
Component

lisp.lisp (file)


Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 mockingbird.asd

Location

mockingbird.asd

Systems

mockingbird (system)

Packages

mockingbird-asd


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 mockingbird/src/all/lisp.lisp

Parent

mockingbird/src/all (system)

Location

src/all.lisp

Packages

mockingbird/src/all


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.3 mockingbird/src/methods/lisp.lisp

Parent

mockingbird/src/methods (system)

Location

src/methods.lisp

Packages

mockingbird/src/methods

Exported Definitions
Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

3.1.4 mockingbird/src/functions/lisp.lisp

Parent

mockingbird/src/functions (system)

Location

src/functions.lisp

Packages

mockingbird/src/functions

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

4.1 mockingbird-asd

Source

mockingbird.asd

Use List

Next: , Previous: , Up: Packages   [Contents][Index]

4.2 mockingbird/src/all

Source

lisp.lisp (file)

Nicknames
Use List

Next: , Previous: , Up: Packages   [Contents][Index]

4.3 mockingbird/src/methods

Source

lisp.lisp (file)

Use List
Used By List

mockingbird/src/all

Exported Definitions
Internal Definitions

Previous: , Up: Packages   [Contents][Index]

4.4 mockingbird/src/functions

Source

lisp.lisp (file)

Nickname

mb.functions

Use List
Used By List

mockingbird/src/all

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Special variables

Special Variable: *mock-calls*
Package

mockingbird/src/functions

Source

lisp.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.2 Macros

Macro: verify-first-call-args-for FN-NAME &rest ARGS
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Macro: with-dynamic-mocks (&rest FN-NAMES) &body BODY
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Macro: with-dynamic-stubs (&rest FDEFS) &body BODY
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Macro: with-method-stubs (&rest METHOD-DEFS) &body BODY
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Macro: with-mocks (&rest FN-NAMES) &body BODY

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*.

Package

mockingbird/src/functions

Source

lisp.lisp (file)

Macro: with-stubs (&rest FDEFS) &body BODY

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*.

Package

mockingbird/src/functions

Source

lisp.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.3 Functions

Function: add-methods-for GENERIC-FUNCTION-OBJECT APPLICABLE-METHODS-OBJECTS
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Function: applicable-methods-metaobjects-from METHOD-DEFS
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Function: call-times-for FN-NAME
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: clear-calls ()
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: gf-metaobjects-from METHOD-DEFS
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Function: method-metaobjects-from METHOD-DEFS
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Function: method-spec-from METHOD-DEFS
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Function: nth-mock-args-for N FN-NAME
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: remove-methods-for GENERIC-FUNCTION-OBJECT APPLICABLE-METHODS-OBJECTS
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Function: specializers/list-from METHOD-OBJECTS
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Function: undefined-stub-function-error NAME

The error function for undefined-stub-function.

Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: verify-call-times-for FN-NAME NUMBER
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: verify-nth-call-args-for N FN-NAME &rest ARGS
Package

mockingbird/src/functions

Source

lisp.lisp (file)


Previous: , Up: Exported definitions   [Contents][Index]

5.1.4 Generic functions

Generic Function: generic-function-method-combination-options GENERIC-FUNCTIONS
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Methods
Method: generic-function-method-combination-options (OBJECT generic-function)
Generic Function: generic-function-method-combination-type-name GENERIC-FUNCTIONS
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Methods
Method: generic-function-method-combination-type-name (OBJECT generic-function)
Generic Function: method-combination-options OBJECT
Package

mockingbird/src/methods

Methods
Method: method-combination-options (OBJECT method-combination)
Source

lisp.lisp (file)

Generic Function: method-combination-type-name METHOD-COMBINATION
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Methods
Method: method-combination-type-name (OBJECT method-combination)

Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Functions

Function: defined-fns-bound-p FDEFS
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: flet-spec FN-DEFS
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: fn-names-from FDEFS
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: mock-calls-for FN-NAME

Accessor function for the special *mock-calls* variable. Returns the value associated with the function.

Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: mock-calls-spec-for FN-NAME

Accessor function for the special *mock-calls* variable. Returns the full spec.

Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: mock-fn-registered-p FN
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: rebind-original-fn-bindings-spec FDEFS TEMP-FN-VARS
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: register-mock-call-for FN ARGS
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: replace-fn-bindings-spec FDEFS TEMP-FN-VARS
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: returns-from FDEFS
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: stub-fns-from FDEFS
Package

mockingbird/src/functions

Source

lisp.lisp (file)

Function: undefined-stub-method-error NAME SPECIALIZERS

The error function for undefined-stub-function.

Package

mockingbird/src/methods

Source

lisp.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Generic functions

Generic Function: filter-applicable-methods METHOD-COMB-SPEC COMB-OPTIONS METHOD-OBJECTS SPECIALIZERS
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Methods
Method: filter-applicable-methods METHOD-COMB COMB-OPTIONS METHOD-OBJECTS SPECIALIZERS
Method: filter-applicable-methods (METHOD-COMB-SPEC (eql standard)) COMB-OPTIONS ALL-APPLICABLE-METHODS SPECIALIZERS
Generic Function: method-combination-type-options METHOD-COMBINATION
Package

mockingbird/src/methods

Source

lisp.lisp (file)

Generic Function: undefined-stub-error-specializers CONDITION
Package

mockingbird/src/methods

Methods
Method: undefined-stub-error-specializers (CONDITION undefined-stub-method)
Source

lisp.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.3 Conditions

Condition: undefined-stub-function ()

Error:

Package

mockingbird/src/functions

Source

lisp.lisp (file)

Direct superclasses

undefined-function (condition)

Condition: undefined-stub-method ()

Error:

Package

mockingbird/src/functions

Source

lisp.lisp (file)

Direct superclasses

undefined-function (condition)

Direct methods

undefined-stub-error-specializers (method)

Direct slots
Slot: specializers
Initargs

:specializers

Readers

undefined-stub-error-specializers (generic function)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   F   L   M  
Index Entry  Section

F
File, Lisp, mockingbird.asd: The mockingbird<dot>asd file
File, Lisp, mockingbird/src/all/lisp.lisp: The mockingbird/src/all/lisp<dot>lisp file
File, Lisp, mockingbird/src/functions/lisp.lisp: The mockingbird/src/functions/lisp<dot>lisp file
File, Lisp, mockingbird/src/methods/lisp.lisp: The mockingbird/src/methods/lisp<dot>lisp file

L
Lisp File, mockingbird.asd: The mockingbird<dot>asd file
Lisp File, mockingbird/src/all/lisp.lisp: The mockingbird/src/all/lisp<dot>lisp file
Lisp File, mockingbird/src/functions/lisp.lisp: The mockingbird/src/functions/lisp<dot>lisp file
Lisp File, mockingbird/src/methods/lisp.lisp: The mockingbird/src/methods/lisp<dot>lisp file

M
mockingbird.asd: The mockingbird<dot>asd file
mockingbird/src/all/lisp.lisp: The mockingbird/src/all/lisp<dot>lisp file
mockingbird/src/functions/lisp.lisp: The mockingbird/src/functions/lisp<dot>lisp file
mockingbird/src/methods/lisp.lisp: The mockingbird/src/methods/lisp<dot>lisp file

Jump to:   F   L   M  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   A   C   D   F   G   M   N   R   S   U   V   W  
Index Entry  Section

A
add-methods-for: Exported functions
applicable-methods-metaobjects-from: Exported functions

C
call-times-for: Exported functions
clear-calls: Exported functions

D
defined-fns-bound-p: Internal functions

F
filter-applicable-methods: Internal generic functions
filter-applicable-methods: Internal generic functions
filter-applicable-methods: Internal generic functions
flet-spec: Internal functions
fn-names-from: Internal functions
Function, add-methods-for: Exported functions
Function, applicable-methods-metaobjects-from: Exported functions
Function, call-times-for: Exported functions
Function, clear-calls: Exported functions
Function, defined-fns-bound-p: Internal functions
Function, flet-spec: Internal functions
Function, fn-names-from: Internal functions
Function, gf-metaobjects-from: Exported functions
Function, method-metaobjects-from: Exported functions
Function, method-spec-from: Exported functions
Function, mock-calls-for: Internal functions
Function, mock-calls-spec-for: Internal functions
Function, mock-fn-registered-p: Internal functions
Function, nth-mock-args-for: Exported functions
Function, rebind-original-fn-bindings-spec: Internal functions
Function, register-mock-call-for: Internal functions
Function, remove-methods-for: Exported functions
Function, replace-fn-bindings-spec: Internal functions
Function, returns-from: Internal functions
Function, specializers/list-from: Exported functions
Function, stub-fns-from: Internal functions
Function, undefined-stub-function-error: Exported functions
Function, undefined-stub-method-error: Internal functions
Function, verify-call-times-for: Exported functions
Function, verify-nth-call-args-for: Exported functions

G
Generic Function, filter-applicable-methods: Internal generic functions
Generic Function, generic-function-method-combination-options: Exported generic functions
Generic Function, generic-function-method-combination-type-name: Exported generic functions
Generic Function, method-combination-options: Exported generic functions
Generic Function, method-combination-type-name: Exported generic functions
Generic Function, method-combination-type-options: Internal generic functions
Generic Function, undefined-stub-error-specializers: Internal generic functions
generic-function-method-combination-options: Exported generic functions
generic-function-method-combination-options: Exported generic functions
generic-function-method-combination-type-name: Exported generic functions
generic-function-method-combination-type-name: Exported generic functions
gf-metaobjects-from: Exported functions

M
Macro, verify-first-call-args-for: Exported macros
Macro, with-dynamic-mocks: Exported macros
Macro, with-dynamic-stubs: Exported macros
Macro, with-method-stubs: Exported macros
Macro, with-mocks: Exported macros
Macro, with-stubs: Exported macros
Method, filter-applicable-methods: Internal generic functions
Method, filter-applicable-methods: Internal generic functions
Method, generic-function-method-combination-options: Exported generic functions
Method, generic-function-method-combination-type-name: Exported generic functions
Method, method-combination-options: Exported generic functions
Method, method-combination-type-name: Exported generic functions
Method, undefined-stub-error-specializers: Internal generic functions
method-combination-options: Exported generic functions
method-combination-options: Exported generic functions
method-combination-type-name: Exported generic functions
method-combination-type-name: Exported generic functions
method-combination-type-options: Internal generic functions
method-metaobjects-from: Exported functions
method-spec-from: Exported functions
mock-calls-for: Internal functions
mock-calls-spec-for: Internal functions
mock-fn-registered-p: Internal functions

N
nth-mock-args-for: Exported functions

R
rebind-original-fn-bindings-spec: Internal functions
register-mock-call-for: Internal functions
remove-methods-for: Exported functions
replace-fn-bindings-spec: Internal functions
returns-from: Internal functions

S
specializers/list-from: Exported functions
stub-fns-from: Internal functions

U
undefined-stub-error-specializers: Internal generic functions
undefined-stub-error-specializers: Internal generic functions
undefined-stub-function-error: Exported functions
undefined-stub-method-error: Internal functions

V
verify-call-times-for: Exported functions
verify-first-call-args-for: Exported macros
verify-nth-call-args-for: Exported functions

W
with-dynamic-mocks: Exported macros
with-dynamic-stubs: Exported macros
with-method-stubs: Exported macros
with-mocks: Exported macros
with-stubs: Exported macros

Jump to:   A   C   D   F   G   M   N   R   S   U   V   W  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   *  
S  
Index Entry  Section

*
*mock-calls*: Exported special variables

S
Slot, specializers: Internal conditions
Special Variable, *mock-calls*: Exported special variables
specializers: Internal conditions

Jump to:   *  
S  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   C   M   P   S   U  
Index Entry  Section

C
Condition, undefined-stub-function: Internal conditions
Condition, undefined-stub-method: Internal conditions

M
mockingbird: The mockingbird system
mockingbird-asd: The mockingbird-asd package
mockingbird/src/all: The mockingbird/src/all system
mockingbird/src/all: The mockingbird/src/all package
mockingbird/src/functions: The mockingbird/src/functions system
mockingbird/src/functions: The mockingbird/src/functions package
mockingbird/src/methods: The mockingbird/src/methods system
mockingbird/src/methods: The mockingbird/src/methods package

P
Package, mockingbird-asd: The mockingbird-asd package
Package, mockingbird/src/all: The mockingbird/src/all package
Package, mockingbird/src/functions: The mockingbird/src/functions package
Package, mockingbird/src/methods: The mockingbird/src/methods package

S
System, mockingbird: The mockingbird system
System, mockingbird/src/all: The mockingbird/src/all system
System, mockingbird/src/functions: The mockingbird/src/functions system
System, mockingbird/src/methods: The mockingbird/src/methods system

U
undefined-stub-function: Internal conditions
undefined-stub-method: Internal conditions

Jump to:   C   M   P   S   U