Liking cljdoc? Tell your friends :D

griffin.test.contract


deep-mergeclj/s

(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
sourceraw docstring

default-gen-methodclj/s

(default-gen-method model state)
source

ephemeral-stateclj/s

(ephemeral-state)

An implementation of MockState that does not persist

An implementation of MockState that does not persist
sourceraw docstring

gen-callclj/s

(gen-call model state)

return a generator for a single call to the model

return a generator for a single call to the model
sourceraw docstring

gen-callsclj/s

(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
sourceraw docstring

gen-calls-clj/s

(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
sourceraw docstring

gen-valid-argsclj/s

(gen-valid-args state method)
source

methodclj/s

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

method?clj/s

(method? x)
source

mockclj/s

(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
sourceraw docstring

modelclj/s

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

model?clj/s

(model? x)
source

protocol?clj/s

(protocol? x)
source

recompute-stateclj/s

(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
sourceraw docstring

ref-stateclj

(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
sourceraw docstring

ref?clj

(ref? x)
source

returnclj/s

(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
sourceraw docstring

return?clj/s

(return? x)
source

test-modelclj/s

(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
sourceraw docstring

test-proxyclj/s

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

  • return: :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.
sourceraw docstring

validate!clj/s

(validate! spec x)
(validate! spec x error-message)
source

var->symclj/s

(var->sym v)
source

verifyclj/s

(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
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close