(deep-merge & maps)Like merge, but merges maps recursively. Copied from griffin.util.map
Like merge, but merges maps recursively. Copied from griffin.util.map
(ephemeral-state)An implementation of MockState that does not persist
An implementation of MockState that does not persist
(gen-call model state)return a generator for a single call to the model
return a generator for a single call to the model
(gen-calls model state & {:keys [max-length] :or {max-length 10}})Generate a seq of calls that shrinks properly
Generate a seq of calls that shrinks properly
(gen-calls- model state length)Given a model instance, return a sequence of maps containing
:method, :arguments and the model's expected return
spec. Satisfies valid-call-sequence?, but does not shrink properly
Given a model instance, return a sequence of maps containing `:method`, `:arguments` and the model's expected return spec. Satisfies valid-call-sequence?, but does not shrink properly
(method v f & {:keys [requires precondition args]})Defines a model protocol method
v - a protocol method var
f - (Fn [state args] -> Return)
keywords
requires - (fn [state] -> bool) if provided, return whether it's valid to call this method in the current state. Defaults to true
args - (fn [state] -> generator), returns a generator for args to the method. Do not include this
precondition - (fn [state args] -> bool). Return truthy if it's valid to call this method with these args in the current state.
Defines a model protocol method v - a protocol method _var_ f - (Fn [state args] -> `Return`) keywords requires - (fn [state] -> bool) if provided, return whether it's valid to call this method in the current state. Defaults to `true` args - (fn [state] -> generator), returns a generator for args to the method. Do not include `this` precondition - (fn [state args] -> bool). Return truthy if it's valid to call this method with these args in the current state.
(mock model & {:keys [mock-state seed] :or {mock-state (ephemeral-state)}})Given a model, return an instance of the protocol.
Options:
mock-state: an instance of mock-protocol/State, used to control the lifetime of mock state. See c/ref-state
seed: an RNG seed to pass to gen/generate, for deterministic results inside a generative test
Given a model, return an instance of the protocol. Options: mock-state: an instance of `mock-protocol/State`, used to control the lifetime of mock state. See `c/ref-state` seed: an RNG seed to pass to `gen/generate`, for deterministic results inside a generative test
(model & {:keys [methods protocols initial-state gen-method cleanup] :as args})Define a model
methods - a coll-of Method
protocols - the set of protocols to be tested
initial-state - (fn [] -> state)
gen-method - (fn [] -> generator). Optional. If not provided, defaults to a generator that selects from all methods which return requires -> true with uniform probability
cleanup - (fn [impl calls] -> any) Optional.
Define a model methods - a coll-of `Method` protocols - the set of protocols to be tested initial-state - (fn [] -> state) gen-method - (fn [] -> generator). Optional. If not provided, defaults to a generator that selects from all methods which return `requires` -> true with uniform probability cleanup - `(fn [impl calls] -> any)` Optional.
(recompute-state model calls)Given a seq of calls that has been modified, recompute state. Returns the calls or nil if a precondition failed
Given a seq of calls that has been modified, recompute state. Returns the calls or nil if a precondition failed
(ref-state r)Returns an implementation of MockState that simulates state living longer than the lifetime of a single mock instance (e.g a database client & its backing database). Pass in a ref that you use to manage the lifetime of mock state
Returns an implementation of MockState that simulates state living longer than the lifetime of a single mock instance (e.g a database client & its backing database). Pass in a ref that you use to manage the lifetime of mock state
(return spec & {:keys [next-state gen]})Define a return value for a model method. Model methods must always return an instance of return.
spec - a spec or predicate used for validating the implementation's return value
next state - the model's next state
gen - A generator used to construct mock return value. If not specified, spec must gen
Define a return value for a model method. Model methods must always return an instance of `return`. spec - a spec or predicate used for validating the implementation's return value next state - the model's next state gen - A generator used to construct mock return value. If not specified, `spec` must gen
(test-model model)Defines a property checking the model. Put it in a defspec
Defines a property checking the model. Put it in a defspec
(test-proxy model
impl
&
{:keys [return mock-state]
:or {return :implementation mock-state (ephemeral-state)}})Given a model and an implementation, return a new implementation of the protocol that passes all calls to the implementation, checking return values against the model. Function calls will throw when the implementation return value does not conform to the model return spec. Prefer this in all non-contract tests to identify discrepancies between the model and implementation.
Options:
:model, :implementation. Selects which return value to return to the caller. defaults to :implementation.Given a model and an implementation, return a new implementation of the protocol that passes all calls to the implementation, checking return values against the model. Function calls will throw when the implementation return value does not conform to the model return spec. Prefer this in all non-contract tests to identify discrepancies between the model and implementation. Options: - return: `:model`, `:implementation`. Selects which return value to return to the caller. defaults to :implementation.
(verify model impl-f & {:keys [num-calls] :or {num-calls 10} :as _opts})Verify an implementation of a protocol against a model. Returns a property, put it in a defspec
impl-f: a no argument constructor of the implementation
num-calls: maximum call length to generate in a single run
Tests the implementation against a sequence of calls from the model
Verify an implementation of a protocol against a model. Returns a _property_, put it in a `defspec` impl-f: a no argument constructor of the implementation num-calls: maximum call length to generate in a single run Tests the implementation against a sequence of calls from the model
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |