A collection of functions for creating and querying stubs, spies, and mocks.
A collection of functions for creating and querying stubs, spies, and mocks.
A Matcher
that always returns true.
A [[Matcher]] that always returns true.
(call-count aspy avar)
(call-count aspy avar args)
Given a spy
, a var, and an optional vector of args, return the number of times the spy received
the method. If given args, filters the list of calls by matching the given args. Matched args may implement the
Matcher
protocol; the default implementation for Object
is =
.
Given a [[spy]], a var, and an optional vector of args, return the number of times the spy received the method. If given args, filters the list of calls by matching the given args. Matched args may implement the [[Matcher]] protocol; the default implementation for `Object` is `=`.
A protocol for defining argument equality matching. Default implementations are provided for Object
(equality),
Pattern
(regexp matching), and IFn
(execution). There is also a wildcard matcher, anything
.
A protocol for defining argument equality matching. Default implementations are provided for `Object` (equality), `Pattern` (regexp matching), and `IFn` (execution). There is also a wildcard matcher, [[anything]].
(matches? matcher value)
(mock & protos-and-impls)
Given a protocol and a hashmap of function implementations, returns a new implementation of that protocol with those
implementations. The returned implementation is also a spy, allowing you to inspect and assert against its calls.
See spy
and stub
.
Given a protocol and a hashmap of function implementations, returns a new implementation of that protocol with those implementations. The returned implementation is also a spy, allowing you to inspect and assert against its calls. See [[spy]] and [[stub]].
(protocols o)
Given an object, attempt to return the set of all protocols it reifies. Warning: this may choke on nonstandard package and namespace choices. Pull requests and bug reports welcome.
Given an object, attempt to return the set of all protocols it reifies. Warning: this may choke on nonstandard package and namespace choices. Pull requests and bug reports welcome.
(received? aspy avar)
(received? aspy avar args)
Given a spy
and a method reference, return true if the method has been called on the spy at least once. If given
args, filters the list of calls by matching the given args. Matched args may implement the Matcher
protocol;
the default implementation for Object
is =
.
Given a [[spy]] and a method reference, return true if the method has been called on the spy at least once. If given args, filters the list of calls by matching the given args. Matched args may implement the [[Matcher]] protocol; the default implementation for `Object` is `=`.
(returning s proto new-stubs)
Given a stub
or mock
, a protocol, and a hashmap of implementations, return a new stub that replaces the stubs
for the named function with the given stubs.
Given a [[stub]] or [[mock]], a protocol, and a hashmap of implementations, return a new stub that replaces the stubs for the named function with the given stubs.
A protocol shared by spies.
A protocol shared by spies.
(calls t)
Returns a map of function names to lists of received args, one for each time the function is called.
Returns a map of function names to lists of received args, one for each time the function is called.
(proxied t)
Returns the underlying object this spy proxies its calls to.
Returns the underlying object this spy proxies its calls to.
(spy o)
(spy o protos)
Given an object implementing one or more protocols, returns a new object that records each call to underlying
protocol functions, then proxies to the original implementation. The returned object also implements Spy
, which
exposes those calls. If an explicit list of protocols is not given, the list will be inferred from the given object.
For spies with added implementation, see mock
. For queryies against spies, see call-count
and received?
.
Given an object implementing one or more protocols, returns a new object that records each call to underlying protocol functions, then proxies to the original implementation. The returned object also implements `Spy`, which exposes those calls. If an explicit list of protocols is not given, the list will be inferred from the given object. For spies with added implementation, see [[mock]]. For queryies against spies, see [[call-count]] and [[received?]].
A protocol shared by stubs.
A protocol shared by stubs.
(all-stubs t)
Returns a normalized hashmap of all known stubs prior to reification.
Returns a normalized hashmap of all known stubs prior to reification.
(stub & protos-and-impls)
Given a variable number of protocols, each followed by an optional hashmap of simple implementations, returns a new
object implementing those protocols. Where no function implementation is provided, calls to that protocol function
will return nil
rather than raising IllegalArgumentException
. Functions as values are not supported, as they
require side effects to define; for more complex stubs, prefer using reify
. For stubs with call count recording,
use mock
.
Given a variable number of protocols, each followed by an optional hashmap of simple implementations, returns a new object implementing those protocols. Where no function implementation is provided, calls to that protocol function will return `nil` rather than raising `IllegalArgumentException`. Functions as values are not supported, as they require side effects to define; for more complex stubs, prefer using `reify`. For stubs with call count recording, use [[mock]].
(throws throwable-class & args)
Given a class and a list of constructor args, returns an object that, when used as part of a stub
construct, will
create and then throw a Throwable of the given type, constructed with the given args.
Given a class and a list of constructor args, returns an object that, when used as part of a [[stub]] construct, will create and then throw a Throwable of the given type, constructed with the given args.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close