Liking cljdoc? Tell your friends :D

lazytest.extensions.expectations

Adapts Expectations v2 (https://github.com/clojure-expectations/clojure-test) to Lazytest.

Adapts Expectations v2 (https://github.com/clojure-expectations/clojure-test) to Lazytest.
raw docstring

=?cljmacro

(=? e a msg)
(=? e a form' msg)
source

=?-implclj

(=?-impl {:keys [e e# a a# conform?]})
source

approximatelyclj

(approximately v)
(approximately v d)

Given a value and an optional delta (default 0.001), return a predicate that expects its argument to be within that delta of the given value.

Given a value and an optional delta (default 0.001), return a predicate
that expects its argument to be within that delta of the given value.
sourceraw docstring

betweenclj

(between a b)

Given a pair of (numeric) values, return a predicate that expects its argument to be be those values or between them -- inclusively.

Given a pair of (numeric) values, return a predicate that expects its
argument to be be those values or between them -- inclusively.
sourceraw docstring

between'clj

(between' a b)

Given a pair of (numeric) values, return a predicate that expects its argument to be (strictly) between those values -- exclusively.

Given a pair of (numeric) values, return a predicate that expects its
argument to be (strictly) between those values -- exclusively.
sourceraw docstring

defexpectcljmacro

(defexpect n & body)

Given a name (a symbol that may include metadata) and a test body, produce a standard lazytest.core test var (using defdescribe).

(defexpect name expected actual) is a special case shorthand for (defexpect name (expect expected actual)) provided as an easy way to migrate legacy Expectation tests to the 'lazytest.core' compatibility version.

Given a name (a symbol that may include metadata) and a test body,
produce a standard `lazytest.core` test var (using `defdescribe`).

`(defexpect name expected actual)` is a special case shorthand for
`(defexpect name (expect expected actual))` provided as an easy way to migrate
legacy Expectation tests to the 'lazytest.core' compatibility version.
sourceraw docstring

expectcljmacro

(expect a)
(expect e a)
(expect e a msg)
(expect e a msg ex? e')

Translate Expectations DSL to lazytest.core language.

These are approximate translations for the most basic forms:

(expect actual) => (expect actual)

(expect expected actual) => (expect (= expected actual))

(expect predicate actual) => (expect (predicate actual))

(expect regex actual) => (expect (re-find regex actual))

(expect ClassName actual) => (expect (instance? ClassName actual))

(expect ExceptionType actual) => (expect (thrown? ExceptionType actual))

(expect spec actual) => (expect (s/valid? spec actual))

An optional third argument can be provided: a message to be included in the output if the test fails.

In addition, actual can be (from-each [x coll] (computation-of x)) or (in set-of-results) or (in larger-hash-map).

Also, expect can be one of (more predicate1 .. predicateN), (more-> exp1 expr1 .. expN exprN) where actual is threaded through each expression exprX and checked with the expected value expX, or (more-of binding exp1 val1 .. expN valN) where actual is destructured using the binding and then each expected value expX is used to check each valX -- expressions based on symbols in the binding.

Translate Expectations DSL to `lazytest.core` language.

These are approximate translations for the most basic forms:

`(expect actual)`               => `(expect actual)`

`(expect expected actual)`      => `(expect (= expected actual))`

`(expect predicate actual)`     => `(expect (predicate actual))`

`(expect regex actual)`         => `(expect (re-find regex actual))`

`(expect ClassName actual)`     => `(expect (instance? ClassName actual))`

`(expect ExceptionType actual)` => `(expect (thrown? ExceptionType actual))`

`(expect spec actual)`          => `(expect (s/valid? spec actual))`

An optional third argument can be provided: a message to be included
in the output if the test fails.

In addition, `actual` can be `(from-each [x coll] (computation-of x))`
or `(in set-of-results)` or `(in larger-hash-map)`.

Also, `expect` can be one of `(more predicate1 .. predicateN)`,
`(more-> exp1 expr1 .. expN exprN)` where `actual` is threaded through
each expression `exprX` and checked with the expected value `expX`,
or `(more-of binding exp1 val1 .. expN valN)` where `actual` is
destructured using the `binding` and then each expected value `expX`
is used to check each `valX` -- expressions based on symbols in the
`binding`.
sourceraw docstring

expectingcljmacro

(expecting string & body)

The Expectations version of lazytest.core/describe.

The Expectations version of `lazytest.core/describe`.
sourceraw docstring

from-eachcljmacro

(from-each bindings & body)

(expect expected (from-each [v coll] (f v))) -- expect this to be true for each element of collection. (f v) is the actual result.

Equivalent to: (doseq [v coll] (expect expected (f v)))

(expect even? (from-each [v (range 10)] (* 2 v)))

from-each may only be used inside expect and is a purely syntactic construct. This macro can be refer'd to satisfy tooling like clj-kondo.

`(expect expected (from-each [v coll] (f v)))` -- expect this to be true
for each element of collection. `(f v)` is the actual result.

Equivalent to: `(doseq [v coll] (expect expected (f v)))`

`(expect even? (from-each [v (range 10)] (* 2 v)))`

`from-each` may only be used inside `expect` and is a purely syntactic construct.
This macro can be `refer`'d to satisfy tooling like `clj-kondo`.
sourceraw docstring

functionallyclj

(functionally expected-fn actual-fn)
(functionally expected-fn actual-fn difference-fn)

Given a pair of functions, return a custom predicate that checks that they return the same result when applied to a value. May optionally accept a 'difference' function that should accept the result of each function and return a string explaininhg how they actually differ. For explaining strings, you could use expectations/strings-difference. (only when I port it across!)

Right now this produces pretty awful failure messages. FIXME!

Given a pair of functions, return a custom predicate that checks that they
return the same result when applied to a value. May optionally accept a
'difference' function that should accept the result of each function and
return a string explaininhg how they actually differ.
For explaining strings, you could use expectations/strings-difference.
(only when I port it across!)

Right now this produces pretty awful failure messages. FIXME!
sourceraw docstring

incljmacro

(in coll)

(expect expected (in actual)) -- expect a subset of a collection.

If actual is a hash map, expected can be a hash map of key/value pairs that you expect to be in the actual result (there may be other key/value pairs, which are ignored).

If actual is a set, vector, or list, expected can be any value that you expect to be a member of the actual data.

(expect {:b 2} (in {:a 1 :b 2 :c 3})) (expect 2 (in #{1 2 3})) (expect 2 (in [1 2 3]))

in may only be used inside expect and is a purely syntactic construct. This macro can be refer'd to satisfy tooling like clj-kondo.

`(expect expected (in actual))` -- expect a subset of a collection.

If `actual` is a hash map, `expected` can be a hash map of key/value pairs
that you expect to be in the `actual` result (there may be other key/value
pairs, which are ignored).

If `actual` is a set, vector, or list, `expected` can be any value that
you expect to be a member of the `actual` data.

`(expect {:b 2} (in {:a 1 :b 2 :c 3}))`
`(expect 2 (in #{1 2 3}))`
`(expect 2 (in [1 2 3]))`

`in` may only be used inside `expect` and is a purely syntactic construct.
This macro can be `refer`'d to satisfy tooling like `clj-kondo`.
sourceraw docstring

morecljmacro

(more & expecteds)

(expect (more expected1 ...) actual) -- provide multiple expectations on actual as a series of expected results.

Equivalent to: (do (expect expected1 actual) ...)

(expect (more int? even?) 42)

more may only be used inside expect and is a purely syntactic construct. This macro can be refer'd to satisfy tooling like clj-kondo.

`(expect (more expected1 ...) actual)` -- provide multiple expectations
on `actual` as a series of expected results.

Equivalent to: `(do (expect expected1 actual) ...)`

`(expect (more int? even?) 42)`

`more` may only be used inside `expect` and is a purely syntactic construct.
This macro can be `refer`'d to satisfy tooling like `clj-kondo`.
sourceraw docstring

more->cljmacro

(more-> & expected-threaded-pairs)

(expect (more-> expected1 (threaded1) ...) actual) -- provide multiple expectations on actual based on threading it into various expressions.

Equivalent to: (do (expect expected1 (-> actual (threaded1))) ...)

(expect (more-> string? (first) int? (second)) ["test" 42])

more-> may only be used inside expect and is a purely syntactic construct. This macro can be refer'd to satisfy tooling like clj-kondo.

`(expect (more-> expected1 (threaded1) ...) actual)` -- provide multiple
expectations on `actual` based on threading it into various expressions.

Equivalent to: `(do (expect expected1 (-> actual (threaded1))) ...)`

`(expect (more-> string? (first) int? (second)) ["test" 42])`

`more->` may only be used inside `expect` and is a purely syntactic construct.
This macro can be `refer`'d to satisfy tooling like `clj-kondo`.
sourceraw docstring

more-ofcljmacro

(more-of destructuring & expected-actual-pairs)

(expect (more-of destructuring expected1 actual1 ...) actual) -- provide multiple expectations on actual based on binding it against the destructuring expression (like in a let) and then expecting things about its subcomponents.

Equivalent to: (let [destructuring actual] (expect expected1 actual1) ...)

(expect (more-of [a b] string? a int? b) ["test" 42])

more-of may only be used inside expect and is a purely syntactic construct. This macro can be refer'd to satisfy tooling like clj-kondo.

`(expect (more-of destructuring expected1 actual1 ...) actual)` -- provide
multiple expectations on `actual` based on binding it against the
`destructuring` expression (like in a `let`) and then expecting things about
its subcomponents.

Equivalent to: `(let [destructuring actual] (expect expected1 actual1) ...)`

`(expect (more-of [a b] string? a int? b) ["test" 42])`

`more-of` may only be used inside `expect` and is a purely syntactic construct.
This macro can be `refer`'d to satisfy tooling like `clj-kondo`.
sourceraw docstring

side-effectscljmacro

(side-effects fn-vec & forms)

Given a vector of functions to track calls to, execute the body.

Returns a vector of each set of arguments used in calls to those functions. The specified functions will not actually be called: only their arguments will be tracked. If you need the call to return a specific value, the function can be given as a pair of its name and the value you want its call(s) to return. Functions given just by name will return nil.

Given a vector of functions to track calls to, execute the body.

Returns a vector of each set of arguments used in calls to those
functions. The specified functions will not actually be called:
only their arguments will be tracked. If you need the call to return
a specific value, the function can be given as a pair of its name
and the value you want its call(s) to return. Functions given just
by name will return `nil`.
sourceraw docstring

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

× close