Liking cljdoc? Tell your friends :D

me.pmatiello.mockfn.xtras


calls-ordered?clj

(calls-ordered? & expected)

Returns whether calls to mock functions occurred in the specified order.

Calls may have other calls between them. Each expected function Var must match exactly; arguments follow the mock argument-matching rules, including argument matchers.

The history of calls may be incomplete when mocked functions are called from threads that do not inherit the current dynamic bindings, such as manually created Thread instances.

Example:

(providing
  [(one-fn :x) :one
   (other-fn :y) :other]
  (one-fn :x) (other-fn :y)
  (is (calls-ordered? [#'one-fn :x] [#'other-fn :y])))
Returns whether calls to mock functions occurred in the specified order.

Calls may have other calls between them. Each expected function Var must
match exactly; arguments follow the mock argument-matching rules, including
argument matchers.

The history of calls may be incomplete when mocked functions are called from
threads that do not inherit the current dynamic bindings, such as manually
created `Thread` instances.

Example:
```
(providing
  [(one-fn :x) :one
   (other-fn :y) :other]
  (one-fn :x) (other-fn :y)
  (is (calls-ordered? [#'one-fn :x] [#'other-fn :y])))
```
sourceraw docstring

reify-withcljmacro

(reify-with protocol mtd->fn)

Creates an object implementing a protocol that delegates to predefined functions any calls performed against the mapped protocol methods.

As the objects produced by this macro always delegate these calls to the specified functions, regular mocking primitives (such as providing, verifying, etc.) can be configured against these given functions in order to specify and validate interactions against the object.

(reify-with ProtocolName {:method-name fn-name ...})

This macro is similar to clojure.core/reify. However, it's also different in the following aspects:

  • It only accepts protocols, not interfaces;
  • It only supports one protocol per instantiation;
  • Methods are not implemented in the body of the declaration but delegated to the given functions instead.

Example:

(defprotocol SomeProtocol
  (m1 [this])
  (m2 [this x]))

(declare fn1 fn2)
(def obj (reify-with SomeProtocol {:m1 fn1 :m2 fn2}))

(providing
  [(fn1 obj) :fn1
   (fn2 obj :x) :fn2]
  (is (= :fn1 (.m1 obj)))
  (is (= :fn2 (.m2 obj :x))))
Creates an object implementing a protocol that delegates to predefined
functions any calls performed against the mapped protocol methods.

As the objects produced by this macro always delegate these calls to the
specified functions, regular mocking primitives (such as providing,
verifying, etc.) can be configured against these given functions in order to
specify and validate interactions against the object.

```
(reify-with ProtocolName {:method-name fn-name ...})
```

This macro is similar to `clojure.core/reify`. However, it's also different
in the following aspects:
- It only accepts protocols, not interfaces;
- It only supports one protocol per instantiation;
- Methods are not implemented in the body of the declaration but delegated to
the given functions instead.

Example:
```
(defprotocol SomeProtocol
  (m1 [this])
  (m2 [this x]))

(declare fn1 fn2)
(def obj (reify-with SomeProtocol {:m1 fn1 :m2 fn2}))

(providing
  [(fn1 obj) :fn1
   (fn2 obj :x) :fn2]
  (is (= :fn1 (.m1 obj)))
  (is (= :fn2 (.m2 obj :x))))
```
sourceraw docstring

return-in-orderclj

(return-in-order & values)

Returns a function that, when called, returns the next value from values on each invocation, cycling through them.

If the next value is a function produced by

Example:

(providing
  [(one-fn :x) (return-in-order :a :b :c (invoke identity))]
  (is (= :a (one-fn :x)))
  (is (= :b (one-fn :x)))
  (is (= :c (one-fn :x)))
  (is (= :x (one-fn :x))))
Returns a function that, when called, returns the next value from `values`
on each invocation, cycling through them.

If the next value is a function produced by
- [[me.pmatiello.mockfn.plain/invoke]], or
- [[me.pmatiello.mockfn.clj-test/invoke]],
then the returned value will be the result of the invocation of this
function with the received call arguments.

Example:
```
(providing
  [(one-fn :x) (return-in-order :a :b :c (invoke identity))]
  (is (= :a (one-fn :x)))
  (is (= :b (one-fn :x)))
  (is (= :c (one-fn :x)))
  (is (= :x (one-fn :x))))
```
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