API for mock - clojure-contrib v1.3 (in development)


Usage:
(ns your-namespace
  (:require clojure.contrib.mock))

Overview





Public Variables and Functions



calls

function
Usage: (calls val)
       (calls val expectation-hash)
Creates or associates to an existing expectation hash the :calls key with a
function that will be called with the given arguments. The return value from
this function will be returned returned by the expected function. If both this
and returns are specified, the return value of "calls" will have precedence.
Usage:
(calls some-fn expectation-hash?)


expect

macro
Usage: (expect expect-bindings & body)
Use expect to redirect calls to dependent functions that are made within the
code under test. Instead of calling the functions that would normally be used,
temporary stubs are used, which can verify function parameters and call counts.
Return values can also be specified as needed.
Usage:
(expect [dep-fn (has-args [arg-pred1] (times n (returns x)))]
  (function-under-test a b c))


has-args

macro
Usage: (has-args arg-pred-forms)
       (has-args arg-pred-forms expect-hash-form)
Creates or associates to an existing expectation hash the :has-args key with
a value corresponding to a function that will either return true if its
argument expectations are met or throw an exception with the details of the
first failed argument it encounters.
Only specify as many predicates as you are interested in verifying. The rest
of the values are safely ignored.
Usage:
(has-args [arg-pred-1 arg-pred-2 ... arg-pred-n] expectation-hash?)


has-matching-signature?

function
Usage: (has-matching-signature? fn-name args)
Calls no-matching-function-signature if no match is found for the given
function. If no argslist meta data is available for the function, it is
not called.


make-arg-checker

function
Usage: (make-arg-checker arg-preds arg-pred-forms)
Creates the argument verifying function for a replaced dependency within
the expectation bound scope. These functions take the additional argument
of the name of the replaced function, then the rest of their args. It is
designed to be called from the mock function generated in the first argument
of the mock info object created by make-mock.


make-count-checker

function
Usage: (make-count-checker pred pred-form)
creates the count checker that is invoked at the end of an expectation, after
the code under test has all been executed. The function returned takes the
name of the associated dependency and the invocation count as arguments.


make-mock

function
Usage: (make-mock fn-name expectation-hash)
creates a vector containing the following information for the named function:
1. dependent function replacement - verifies signature, calls arg checker,
increases count, returns return value.
2. an atom containing the invocation count
3. the invocation count checker function
4. a symbol of the name of the function being replaced.


returns

function
Usage: (returns val)
       (returns val expectation-hash)
Creates or associates to an existing expectation hash the :returns key with
a value to be returned by the expectation after a successful invocation
matching its expected arguments (if applicable).
Usage:
(returns ret-value expectation-hash?)


times

macro
Usage: (times times-fn)
       (times times-fn expectation-hash)
Creates or associates to an existing expectation hash the :times key with a
value corresponding to a predicate function which expects an integer value.
This function can either be specified as the first argument to times or can be
the result of calling times with an integer argument, in which case the
predicate will default to being an exact match.  This predicate is called at
the end of an expect expression to validate that an expected dependency
function was called the expected number of times.
Usage:
(times n)
(times #(> n %))
(times n expectation-hash)


validate-counts

function
Usage: (validate-counts mock-data)
given the sequence of all mock data for the expectation, simply calls the
count checker for each dependency.

mock.test-adapter






calls

function
Usage: (calls val)
       (calls val expectation-hash)
Creates or associates to an existing expectation hash the :calls key with a
function that will be called with the given arguments. The return value from
this function will be returned returned by the expected function. If both this
and returns are specified, the return value of "calls" will have precedence.
Usage:
(calls some-fn expectation-hash?)

has-args

macro
Usage: (has-args arg-pred-forms)
       (has-args arg-pred-forms expect-hash-form)
Creates or associates to an existing expectation hash the :has-args key with
a value corresponding to a function that will either return true if its
argument expectations are met or throw an exception with the details of the
first failed argument it encounters.
Only specify as many predicates as you are interested in verifying. The rest
of the values are safely ignored.
Usage:
(has-args [arg-pred-1 arg-pred-2 ... arg-pred-n] expectation-hash?)

has-matching-signature?

function
Usage: (has-matching-signature? fn-name args)
Calls no-matching-function-signature if no match is found for the given
function. If no argslist meta data is available for the function, it is
not called.

make-arg-checker

function
Usage: (make-arg-checker arg-preds arg-pred-forms)
Creates the argument verifying function for a replaced dependency within
the expectation bound scope. These functions take the additional argument
of the name of the replaced function, then the rest of their args. It is
designed to be called from the mock function generated in the first argument
of the mock info object created by make-mock.

make-count-checker

function
Usage: (make-count-checker pred pred-form)
creates the count checker that is invoked at the end of an expectation, after
the code under test has all been executed. The function returned takes the
name of the associated dependency and the invocation count as arguments.

make-mock

function
Usage: (make-mock fn-name expectation-hash)
creates a vector containing the following information for the named function:
1. dependent function replacement - verifies signature, calls arg checker,
increases count, returns return value.
2. an atom containing the invocation count
3. the invocation count checker function
4. a symbol of the name of the function being replaced.

report-problem

function
Usage: (report-problem fn-name expected actual msg)
This function is designed to be used in a binding macro to override
the report-problem function in clojure.contrib.mock. Instead of printing
the error to the console, the error is logged via clojure.test.
Source

returns

function
Usage: (returns val)
       (returns val expectation-hash)
Creates or associates to an existing expectation hash the :returns key with
a value to be returned by the expectation after a successful invocation
matching its expected arguments (if applicable).
Usage:
(returns ret-value expectation-hash?)

times

macro
Usage: (times times-fn)
       (times times-fn expectation-hash)
Creates or associates to an existing expectation hash the :times key with a
value corresponding to a predicate function which expects an integer value.
This function can either be specified as the first argument to times or can be
the result of calling times with an integer argument, in which case the
predicate will default to being an exact match.  This predicate is called at
the end of an expect expression to validate that an expected dependency
function was called the expected number of times.
Usage:
(times n)
(times #(> n %))
(times n expectation-hash)

validate-counts

function
Usage: (validate-counts mock-data)
given the sequence of all mock data for the expectation, simply calls the
count checker for each dependency.
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.