shrubbery.core
A collection of functions for creating and querying stubs, spies, and mocks.
anything
A Matcher that always returns true.
call-count
(call-count aspy avar)
(call-count aspy avar args)
Matcher
protocol
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.
members
matches?
(matches? matcher value)
mock
(mock & protos-and-impls)
protocol?
(protocol? p)
True if p is a protocol.
protocols
(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.
received?
(received? aspy avar)
(received? aspy avar args)
returning
(returning s proto new-stubs)
Spy
protocol
A protocol shared by spies.
members
calls
(calls t)
Returns a map of function names to lists of received args, one for each time the function is called.
proxied
(proxied t)
Returns the underlying object this spy proxies its calls to.
spy
(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?.
spy?
(spy? s)
True if s reifies Spy.
Stub
protocol
A protocol shared by stubs.
members
all-stubs
(all-stubs t)
Returns a normalized hashmap of all known stubs prior to reification.
stub
(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.
stub?
(stub? s)
True if s reifies Stub.