Liking cljdoc? Tell your friends :D

fhofherr.stub-fn.core

Implements the core functionality of fhofherr/stub-fn.

Users of clojure.test should not use this namespace directly. Instead they should use fhofherr.stub-fn.clojure.test.

The core functionality is implemented by the stub-fn macro. It creates an anonymous function which can be used in place of any other function. The stubbed function tracks information about its invocations under the ::stub-info key in its meta data.

Implements the core functionality of `fhofherr/stub-fn`.

Users of `clojure.test` should not use this namespace directly. Instead
they should use [[fhofherr.stub-fn.clojure.test]].

The core functionality is implemented by the [[stub-fn]] macro. It creates
an anonymous function which can be used in place of any other function. The
stubbed function tracks information about its invocations under the
`::stub-info` key in its meta data.
raw docstring

format-verification-reportclj

(format-verification-report verification-report
                            &
                            {:keys [add-type] :or {add-type false}})

Format the verification report returned by verify-invocations.

Arguments:

  • verification-report: the verification report to format.
  • add-type: whether to add the type of the report, which is either 'Success!' or 'Failure!'. Default false.
Format the verification report returned by [[verify-invocations]].

Arguments:

* `verification-report`: the verification report to format.
* `add-type`: whether to add the type of the report, which is either
  'Success!' or 'Failure!'. Default `false`.
sourceraw docstring

get-stub-fn-nameclj

(get-stub-fn-name stubbed-fn)

Get stubbed-fn's name.

Returns nil if the stubbed-function is not a stub.

Arguments:

  • stubbed-fn: the stubbed function
Get `stubbed-fn`'s name.

Returns `nil` if the `stubbed-function` is not a stub.

Arguments:

* `stubbed-fn`: the stubbed function
sourceraw docstring

get-stub-infoclj

(get-stub-info stubbed-fn)

Get all available information about the stubbed-fn.

Returns nil if the stubbed-function is not a stub.

Arguments:

  • stubbed-fn: the stubbed function
Get all available information about the `stubbed-fn`.

Returns `nil` if the `stubbed-function` is not a stub.

Arguments:

* `stubbed-fn`: the stubbed function
sourceraw docstring

get-stub-invocationsclj

(get-stub-invocations stubbed-fn)

Get all available information about stubbed-fn's invocations.

Returns nil if the stubbed-function is not a stub.

Arguments:

  • stubbed-fn: the stubbed function
Get all available information about `stubbed-fn`'s invocations.

Returns `nil` if the `stubbed-function` is not a stub.

Arguments:

* `stubbed-fn`: the stubbed function
sourceraw docstring

invoked?clj

(invoked? stubbed-fn & {:keys [times args] :or {times 1} :as kwargs})

Check if a stubbed function has been invoked successfully.

Returns true if the stubbed function was invoked as expected.

Takes the same arguments as verify-invocations.

Check if a stubbed function has been invoked successfully.

Returns `true` if the stubbed function was invoked as expected.

Takes the same arguments as [[verify-invocations]].
sourceraw docstring

stub-fnclj/smacro

(stub-fn fn-name fn-args & fn-body)

Define an anonymous function that can be used as a stub for another function.

Can be used almost like fn. The only difference is, that a function name is required. This makes it easier to produce meaningful stack traces and failure reports.

Internally stub-fn uses fn to create an anonymous function. Various information about the function's invocations is stored in a ref in the function's meta data.

Warning: storing information about function invocations in a ref makes any stubbed function stateful. Avoid to store it in the global context. You should never need to do something like the following:

(def (stub-fn stubbed [] ...))

Arguments:

  • fn-name: symbol identifying the function stub
  • fn-args: argument vector of the stubbed function
  • fn-body: body of the function stub (optional).
Define an anonymous function that can be used as a stub for another function.

Can be used almost like `fn`. The only difference is, that a function name
is required. This makes it easier to produce meaningful stack traces and
failure reports.

Internally `stub-fn` uses `fn` to create an anonymous function. Various
information about the function's invocations is stored in a `ref` in the
function's meta data.

**Warning**: storing information about function invocations in a `ref` makes
any stubbed function *stateful*. Avoid to store it in the global context.
You should *never* need to do something like the following:

```clojure
(def (stub-fn stubbed [] ...))
```

Arguments:

* `fn-name`: symbol identifying the function stub
* `fn-args`: argument vector of the stubbed function
* `fn-body`: body of the function stub (optional).
sourceraw docstring

stub?clj

(stub? f)

Check if the function f is a stub.

Return true if f is a stub, or false otherwise.

Arguments:

  • f: a function that may be a stub
Check if the function `f` is a stub.

Return `true` if `f` is a stub, or `false` otherwise.

Arguments:

* `f`: a function that may be a stub
sourceraw docstring

success?clj

(success? verification-report)
source

verify-invocationsclj

(verify-invocations stubbed-fn & {:keys [times args] :or {times 1}})

Check if the function stubbed-fn has been invoked.

If the times keyword argument is given verify-invocations will test if stubbed-fn has been invoked the expected number of times.

If the args keyword argument is given verify-invocations will test if stubbed-fn has been invoked with the expected arguments.

If both args and times are given verify-invocations checks if the function has been invoked the expected number of times with the expected arguments. This means that the function may have been additionally invoked with different arguments an arbitrary number of times.

Arguments:

  • stubbed-fn: the stubbed function.

Keyword arguments:

  • times: expected number of invocations. Defaults to 1.
  • args: map of expected arguments to the function invocation.
Check if the function `stubbed-fn` has been invoked.

If the `times` keyword argument is given `verify-invocations` will test if 
`stubbed-fn` has been invoked the expected number of times.

If the `args` keyword argument is given `verify-invocations` will test if
`stubbed-fn` has been invoked with the expected arguments.

If both `args` and `times` are given `verify-invocations` checks if the
function has been invoked the expected number of times with the expected
arguments. This means that the function may have been additionally invoked
with different arguments an arbitrary number of times.

Arguments:

* `stubbed-fn`: the stubbed function.

Keyword arguments:

* `times`: expected number of invocations. Defaults to 1.
* `args`: map of expected arguments to the function invocation.
sourceraw docstring

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

× close