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)

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

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)

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.

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)

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

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

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.