spy.core
A testing framework for stubs, spies and mocks.
Enables verification of interactions with a function.
call-count
(call-count f)
Returns the count of the number of calls to the spy f.
called-at-least-n-times?
(called-at-least-n-times? f n)
Returns true if the spy f was called at least n times, false if not.
called-at-least-once?
(called-at-least-once? f)
Returns true if the spy f was called at least once, false if not.
called-n-times?
(called-n-times? f n)
Returns true if the spy f was called n times, false if not.
called-no-more-than-n-times?
(called-no-more-than-n-times? f n)
Returns true if the spy f was called no more than n times, false if not.
called-no-more-than-once?
(called-no-more-than-once? f)
Returns true if the spy f was called once or not at all, false if not.
called-once-with?
(called-once-with? f & args)
Returns true if there was only one call to the spy f and the args match, false if not.
called-once?
(called-once? f)
Returns true if the spy f was called once, false if not.
called-with?
(called-with? f & args)
Returns true if any of the calls to the spy f match the args, false if no calls match.
called?
(called? f)
Returns true is the spy f was called, false if not.
calls
(calls f)
Returns a list of all calls to the spy f.
first-call
(first-call f)
Returns the first call to the spy f
first-response
(first-response f)
Returns the first response returned by the spy f.
last-call
(last-call f)
Returns the last call to the spy f
last-response
(last-response f)
Returns the last response returned by the spy f.
mock
(mock f)
An alias for spy, behaviour for the function is provided by the user.
not-called-with?
(not-called-with? f & args)
Returns true if the no calls to the spy f match the args, false if a call matches.
not-called?
(not-called? f)
Returns true if the spy f was never called, false if not.
nth-call
(nth-call f n)
Returns the nth call to the spy f for the index n.
nth-response
(nth-response f n)
Returns the response of the spy f at the index n.
reset-spy!
(reset-spy! f)
Resets the calls and responses on the spy f.
responses
(responses f)
Returns a list of all responses returned by the spy f.
spy
(spy)
(spy f)
If no function is supplied, returns a function that takes any number of args
and returns nil.
If a function is supplied, returns a function that wraps the function.
Adds metadata {:calls (atom []) :responses (atom [])} to the function, calls
and responses are recorded and stored inside the atoms.
If an exception is thrown by the function this is caught, recorded as a response
nested in a map under the key :thrown, and rethrown.
stub
(stub)
(stub value)
Returns a spy function that returns the value supplied, or nil
if no value is supplied.
stub-throws
(stub-throws exception)
Returns a spy function that throws the exception provided.