Liking cljdoc? Tell your friends :D

net.lewisship.test-pipeline

Per-test pipeline of composable steps, including simple mocks and capturing of logging events.

A test is implemented as series of step functions; each step receives a context map, does work, and passes the (sometimes modified) context map to the next step.

The goal is to make tests flatter (fewer nested scopes), more readable, and to make various kinds of steps more composable.

Per-test pipeline of composable steps, including simple mocks and capturing of logging events.

A test is implemented as series of step functions; each step receives a context map, does work, and passes
the (sometimes modified) context map to the next step.

The goal is to make tests flatter (fewer nested scopes), more
readable, and to make various kinds of steps more composable.
raw docstring

add-halt-checkclj/s

(add-halt-check context check-fn)

Adds a halt check function to the context, for use by continue.

Returns the updated context, which should then be passed to continue.

Adds a halt check function to the context, for use by [[continue]].

Returns the updated context, which should then be passed to `continue`.
sourceraw docstring

assoc-in-contextclj/s

(assoc-in-context ks v)

Returns a step function that performs an assoc-in on the context during execution.

Returns a step function that performs an `assoc-in` on the context during execution.
sourceraw docstring

bindclj/smacro

(bind bind-var bound-value)

Evaluates to a step function that binds the variable to a value before continuing.

Evaluates to a step function that binds the variable to a value before continuing.
sourceraw docstring

callsclj/smacro

(calls context spy-var)

Returns calls to-date of the given spy, clearing the list of calls as a side effect.

Returns a vector of lists of arguments.

Returns calls to-date of the given spy, clearing the list of calls as a side effect.

Returns a vector of lists of arguments.
sourceraw docstring

capture-loggingclj

(capture-logging context)

A step function that captures logging events from clojure.tools.logging. Use the clojure.tools.logging.test namespace to query what has been logged.

A step function that captures logging events from `clojure.tools.logging`.
Use the `clojure.tools.logging.test` namespace to query what has been logged.
sourceraw docstring

cleanupclj/smacro

(cleanup & exprs)

Creates a try/finally to execute the provided cleanup expressions after the pipeline has finished executing.

Creates a try/finally to execute the provided cleanup expressions after the pipeline has finished executing.
sourceraw docstring

context-isclj/smacro

(context-is context-symbol expr)
(context-is context-symbol expr message)

Variant of is where a local binding for the context is provided.

Example:

(context-is context (valid? (:result context)) "expected valid result")

The expression and optional message are passed to clojure.test/is.

The context is then passed, unchanged, to continue.

Variant of [[is]] where a local binding for the context is provided.

Example:

    (context-is context (valid? (:result context)) "expected valid result")

The expression and optional message are passed to `clojure.test/is`.

The context is then passed, unchanged, to [[continue]].
sourceraw docstring

continueclj/s

(continue context)

Called from a step function to pass the context to the next step function in the pipeline. Does nothing if there are no more steps to execute.

continue is responsible for halt checks; each added halt check function is passed the context, and if any of them return a truthy value, the pipeline is halted, as with halt.

Called from a step function to pass the context to the next step function in the pipeline.
Does nothing if there are no more steps to execute.

continue is responsible for halt checks; each added halt check function is passed the context, and
if any of them return a truthy value, the pipeline is halted, as with [[halt]].
sourceraw docstring

executeclj/s

(execute & steps)

The main entrypoint: executes a sequence of step functions as a pipeline.

Each step in steps may be a step function, or nil, or a seq of steps (recursively). The provided seq is flattened and nils are removed before constructing the final pipeline.

A step function is responsible for one portion of setting up the test environment, and may perform part of the test execution as well. Generally, the final step function is the most specific to a particular test, and will be where most assertions occur.

A step function is passed a context; the step function's job is to modify the context before passing the context to continue; this call is often wrapped in a try (to clean up resources) and/or with-redefs (to override functions for testing).

Each step function must call continue (except the final step function, for which the call to continue is optional and does nothing); however this check is skipped if the execution pipeline is halted.

The main entrypoint: executes a sequence of step functions as a pipeline.

Each step in `steps` may be a step function, or nil, or a seq of steps (recursively).
The provided seq is flattened and nils are removed before constructing the final pipeline.

A step function is responsible for one portion of setting up the test environment, and may perform part of the
test execution as well. Generally, the final step function is the most specific to a particular test,
and will be where most assertions occur.

A step function is passed a context; the step function's job is to modify the context before
passing the context to `continue`; this call is often wrapped
in a `try` (to clean up resources) and/or `with-redefs` (to override functions for testing).

Each step function must call [[continue]] (except the final step function,
for which the call to `continue` is optional and does nothing); however this check is skipped if
the execution pipeline is halted.
sourceraw docstring

haltclj/s

(halt context)

Called instead of continue to immediately halt the execution of the pipeline without executing any further steps. This is used when an error has been detected that will invalidate behavior checks in later steps.

When execution is halted, the check that ensures all steps executed is disabled.

Called instead of [[continue]] to immediately halt the execution of the pipeline without
executing any further steps. This is used when an error has been detected that will invalidate
behavior checks in later steps.

When execution is halted, the check that ensures all steps executed is disabled.
sourceraw docstring

halt-on-failureclj/s

(halt-on-failure context)

Adds a halt check that terminates the pipeline if any test errors or test failures are subsequently reported.

Adds a halt check that terminates the pipeline if any test errors or
test failures are subsequently reported.
sourceraw docstring

isclj/smacro

(is expr)
(is expr message)

Wrapper around clojure.test/is.

Wrapper around clojure.test/is.
sourceraw docstring

matches?clj/smacro

(matches? context-symbol pattern expression)
(matches? context-symbol pattern expression message)

A wrapper around (context-is ... (match? ...)) where match? is supplied by nubank/matcher-combinators.

Example: (p/matches? context {:truth :beauty} (:statement context))

The context is bound to the provided symbol, which is available to use with the pattern ({:truth :beauty}) and the expression ((:statement context)).

A wrapper around `(context-is ... (match? ...))` where `match?` is supplied by
nubank/matcher-combinators.

Example:
  (p/matches? context {:truth :beauty} (:statement context))

The context is bound to the provided symbol, which is available to use with
the pattern (`{:truth :beauty}`) and the expression (`(:statement context)`).
sourceraw docstring

mockclj/smacro

(mock mock-var mock-fn)

Expands to a step function that mocks the var with the corresponding value (as with clojure.core/with-redefs).

Expands to a step function that mocks the var with the corresponding value
(as with `clojure.core/with-redefs`).
sourceraw docstring

providingclj/smacro

(providing bindings)

Wrapper around mockfn.macros/providing. The argument is the bindings vector.

Wrapper around mockfn.macros/providing.  The argument is the bindings vector.
sourceraw docstring

reportingclj/smacro

(reporting k)

Expands to a step function based on com.walmartlabs.test-reporting/reporting that extracts a value from the context and reports its value if a test fails.

Expands to a step function based on `com.walmartlabs.test-reporting/reporting` that extracts a value from the context and reports its value
if a test fails.
sourceraw docstring

splitclj/s

(split step-fns)

Splits the execution pipeline. Returns a step function that will sequence through the provided seq of step fns and pass the context to each in turn.

Thus, any steps further down the pipeline will be invoked multiple times.

Splits the execution pipeline.  Returns a step function that will sequence through
the provided seq of step fns and pass the context to each in turn.

Thus, any steps further down the pipeline will be invoked multiple times.
sourceraw docstring

spyclj/smacro

(spy spy-var)
(spy spy-var mock-fn)

Expands to a step function that mocks a function with a spy.

The spy records into an atom each list of arguments it is passed, before passing the arguments to the spied function.

Optionally, a mock function (as with mock) can be supplied to replace the spied function.

Usage:

  (spy db/put-row (fn [_ row-data] ...))

The calls macro retrieves the calls made to the spy.

Expands to a step function that mocks a function with a spy.

The spy records into an atom each list of arguments it is passed, before passing the arguments to the spied function.

Optionally, a mock function (as with [[mock]]) can be supplied to replace the spied function.

Usage:
```
  (spy db/put-row (fn [_ row-data] ...))
```

The [[calls]] macro retrieves the calls made to the spy.
sourceraw docstring

testingclj/smacro

(testing expr)

Wrapper around clojure.test/testing.

Wrapper around clojure.test/testing.
sourceraw docstring

thenclj/smacro

(then & exprs)

Evaluates the provided expressions during execution, before continuing to the next test step function.

Evaluates the provided expressions during execution, before continuing to the next test step function.
sourceraw docstring

update-in-contextclj/s

(update-in-context ks f & args)

Returns a step function that performs an update-in on the context during execution.

Returns a step function that performs an `update-in` on the context during execution.
sourceraw docstring

verifyingclj/smacro

(verifying bindings)

Wrapper around mockfn.macros/verifying. The argument is the bindings vector.

Wrapper around mockfn.macros/verifying.  The argument is the bindings vector.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close