Liking cljdoc? Tell your friends :D

midje.checkers

Checkers are for checking results of checkables, or checking that appropriate arguments are passed to prerequisites

Checkers are for checking results of checkables, or checking
that appropriate arguments are passed to prerequisites
raw docstring

&clj

This var is defined so that Midje prerequisites can use & for optional args without having to quote it.

This var is defined so that Midje prerequisites can use & for optional args without having to quote it.
sourceraw docstring

anythingclj

(anything actual)

Accepts any value.

Accepts any value.
sourceraw docstring

as-checkerclj

(as-checker function)

Label a function as a checker. This is only required if the checker is to be used on the left-hand-side of a prerequisite. See (guide checkers-within-prerequisites). Example:

(fact (f 3) => "odd number received" (provided (g (as-checker odd?)) => "odd number received"))

Label a function as a checker. This is only required if
the checker is to be used on the left-hand-side of a prerequisite.
See `(guide checkers-within-prerequisites)`.
Example:

   (fact (f 3) => "odd number received"
     (provided
       (g (as-checker odd?)) => "odd number received"))
sourceraw docstring

chatty-checkercljmacro

(chatty-checker [actual-arg] [f & args])

Create a function that returns either true or a description of a failure that shows the value of subexpressions. For example, consider this:

(fact 4 => (fn [actual] (< (h actual) (g actual))))

The failure message only tells you that 4 was a failing value. Contrast to the following:

(fact 4 => (chatty-checker [actual] (< (h actual) (g actual))))

The failure output will contain the value of (h actual) and (g actual).

For more, see (guide chatty-checkers).

Note: if you want your checkers to be and or or expressions, use every-checker or some-checker in preference to chatty-checker.

Create a function that returns either true or a description of a failure
 that shows the value of subexpressions. For example, consider this:

   (fact 4 => (fn [actual] (< (h actual) (g actual))))

The failure message only tells you that 4 was a failing value. Contrast
to the following:

   (fact 4 => (chatty-checker [actual] (< (h actual) (g actual))))

The failure output will contain the value of (h actual) and (g actual).

For more, see `(guide chatty-checkers)`.

Note: if you want your checkers to be `and` or `or` expressions, use
`every-checker` or `some-checker` in preference to `chatty-checker`.
sourceraw docstring

checkercljmacro

(checker args & body)

Creates an anonymous function tagged as a checker. Such tagging is only needed if the checker is to be used on the left-hand-side of a prerequisite. See (guide checkers-within-prerequisites). Example: (provided (f (checker [x] (and (pos? x) (even? x)))) => 3)

Creates an anonymous function tagged as a checker. Such tagging is only
needed if the checker is to be used on the left-hand-side of a
prerequisite.  See `(guide checkers-within-prerequisites)`.
Example:
    (provided
       (f (checker [x] (and (pos? x) (even? x)))) => 3)
sourceraw docstring

containsclj

(contains expected)
(contains expected looseness)

Checks that the expected result is a subsequence of the actual result:

To succeed, f's result must be (1) contiguous and (2) in the same order as in the contains clause. Here are examples:

[3 4 5 700] => (contains [4 5 700]) ; true [4 700 5] => (contains [4 5 700]) ; false [4 5 'hi 700] => (contains [4 5 700]) ; false

The :in-any-order modifier loosens the second requirement:

['hi 700 5 4] => (contains [4 5 700] :in-any-order) ; true [4 5 'hi 700] => (contains [4 5 700] :in-any-order) ; false b/c 'hi is in middle

The :gaps-ok modifier loosens the first:

[4 5 'hi 700] => (contains [4 5 700] :gaps-ok) ; true [4 700 'hi' 5] => (contains [4 5 700] :gaps-ok) ; false b/c of bad order

The two modifiers can be used at the same time:

[4 700 5] => (contains [4 5 700] :gaps-ok :in-any-order) ; true [4 5 'hi 700] => (contains [4 5 700] :in-any-order :gaps-ok) ; true [700 'hi 4 5 'hi] => (contains [4 5 700] :in-any-order :gaps-ok) ; true

Another way to indicate :in-any-order is to describe what's contained by a set. The following two are equivalent:

[700 4 5] => (contains [4 5 700] :in-any-order) [700 4 5] => (contains #{4 5 700})

:gaps-ok can be used with a set. (So can :in-any-order, but it has no effect.)

Checks that the expected result is a subsequence of the actual result:

To succeed, f's result must be (1) contiguous and (2) in the
same order as in the contains clause. Here are examples:

   [3 4 5 700]   => (contains [4 5 700]) ; true
   [4 700 5]     => (contains [4 5 700]) ; false
   [4 5 'hi 700] => (contains [4 5 700]) ; false

The :in-any-order modifier loosens the second requirement:

   ['hi 700 5 4] => (contains [4 5 700] :in-any-order) ; true
   [4 5 'hi 700] => (contains [4 5 700] :in-any-order) ; false b/c 'hi is in middle

The :gaps-ok modifier loosens the first:

   [4 5 'hi 700]  => (contains [4 5 700] :gaps-ok) ; true
   [4 700 'hi' 5] => (contains [4 5 700] :gaps-ok) ; false b/c of bad order

The two modifiers can be used at the same time:

   [4 700 5]         => (contains [4 5 700] :gaps-ok :in-any-order) ; true
   [4 5 'hi 700]     => (contains [4 5 700] :in-any-order :gaps-ok) ; true
   [700 'hi 4 5 'hi] => (contains [4 5 700] :in-any-order :gaps-ok) ; true

Another way to indicate :in-any-order is to describe
what's contained by a set. The following two are equivalent:

   [700 4 5] => (contains [4 5 700] :in-any-order)
   [700 4 5] => (contains #{4 5 700})

:gaps-ok can be used with a set. (So can :in-any-order, but it has no effect.)
sourceraw docstring

defcheckercljmacro

(defchecker name docstring? attr-map? bindings+bodies)

Like defn, but tags the variable created and the function it refers to as checkers. This is only required if the checker is to be used in the left-hand side of a prerequisite, but it never hurts to define checkers using this. Here is a checker for positive even numbers:

(defchecker twosie [actual]
   (and (pos? actual) (even? actual)))
(fact 2 => twosie)

Here is the definition of a simple version of the roughly checker:

(defchecker roughly [expected delta] (checker [actual] (and (number? actual) ...))) (fact 1.1 => (roughly 1 0.2))

See also (doc chatty-checker).

Like defn, but tags the variable created and the function it
refers to as checkers. This is only required if the checker is
to be used in the left-hand side of a prerequisite, but it never
hurts to define checkers using this. Here is a checker for
positive even numbers:

    (defchecker twosie [actual]
       (and (pos? actual) (even? actual)))
    (fact 2 => twosie)

 Here is the definition of a simple version of the `roughly`
 checker:

   (defchecker roughly [expected delta]
      (checker [actual]
         (and (number? actual)
              ...)))
  (fact 1.1 => (roughly 1 0.2))

 See also `(doc chatty-checker)`.
sourceraw docstring

eight-ofclj

(eight-of expected)

Checks whether a sequence contains precisely eight results, and that they each match the checker.

Ex. (fact [:a :a :a :a :a :a :a :a] => (eight-of :a))

Checks whether a sequence contains precisely eight results, and 
that they each match the checker.

 Ex. (fact [:a :a :a :a :a :a :a :a] => (eight-of :a))
sourceraw docstring

every-checkercljmacro

(every-checker & checker-forms)

Combines multiple checkers into one checker that passes when all component checkers pass. If one checker fails, the remainder are not run. The output shows which checker failed.

Example:

(fact 3 => (every-checker odd? neg?))
FAIL ...
...
During checking, these intermediate values were seen:
   neg? => false

The combined checkers can include anything that can appear on the right-hand side of an arrow.

Example:

(fact "-1b-" => (every-checker #(= 4 (count %))
                               #"1b"))
Combines multiple checkers into one checker that passes
when all component checkers pass. If one checker fails,
the remainder are not run. The output shows which checker
failed.

Example:

    (fact 3 => (every-checker odd? neg?))
    FAIL ...
    ...
    During checking, these intermediate values were seen:
       neg? => false

The combined checkers can include anything that can appear on the
right-hand side of an arrow.

Example:

    (fact "-1b-" => (every-checker #(= 4 (count %))
                                   #"1b"))
sourceraw docstring

exactlyclj

(exactly expected)

Checks for equality. Use to avoid default handling of functions.

Checks for equality. Use to avoid default handling of functions.
sourceraw docstring

FALSEYclj

(FALSEY actual)

Returns precisely true if actual is nil or false.

Returns precisely true if actual is nil or false.
sourceraw docstring

falseyclj

(falsey actual)

Returns precisely true if actual is nil or false.

Returns precisely true if actual is nil or false.
sourceraw docstring

five-ofclj

(five-of expected)

Checks whether a sequence contains precisely five results, and that they each match the checker.

Ex. (fact [:a :a :a :a :a] => (five-of :a))

Checks whether a sequence contains precisely five results, and 
that they each match the checker.

 Ex. (fact [:a :a :a :a :a] => (five-of :a))
sourceraw docstring

four-ofclj

(four-of expected)

Checks whether a sequence contains precisely four results, and that they each match the checker.

Ex. (fact [:a :a :a :a] => (four-of :a))

Checks whether a sequence contains precisely four results, and 
that they each match the checker.

 Ex. (fact [:a :a :a :a] => (four-of :a))
sourceraw docstring

hasclj

(has quantifier predicate)

You can apply Clojure's quantification functions (every?, some, and so on) to all the values of sequence.

Ex. (fact (f) => (has every? odd?))

You can apply Clojure's quantification functions (every?, some, and so on)
to all the values of sequence.

Ex. (fact (f) => (has every? odd?))
sourceraw docstring

has-prefixclj

(has-prefix expected-prefix)
(has-prefix expected-prefix looseness?)

Checks that the actual result starts with the expected result:

[1 2 3] => (has-prefix [1 2]) ; true [1 2 3] => (has-prefix [2 1]) ; false - order matters [1 2 3] => (has-prefix [2 1] :in-any-order) ; true [1 2 3] => (has-prefix #{2 1}) ; true

Checks that the actual result starts with the expected result:

[1 2 3] => (has-prefix   [1 2]) ; true
[1 2 3] => (has-prefix   [2 1]) ; false - order matters
[1 2 3] => (has-prefix   [2 1] :in-any-order) ; true
[1 2 3] => (has-prefix  #{2 1}) ; true 
sourceraw docstring

has-suffixclj

(has-suffix expected-suffix)
(has-suffix expected-suffix looseness?)

Checks that the actual result ends with the expected result:

[1 2 3] => (has-suffix [2 3]) ; true [1 2 3] => (has-suffix [3 2]) ; false - order matters [1 2 3] => (has-suffix [3 2] :in-any-order) ; true [1 2 3] => (has-suffix #{3 2}) ; true

Checks that the actual result ends with the expected result:

[1 2 3] => (has-suffix   [2 3]) ; true
[1 2 3] => (has-suffix   [3 2]) ; false - order matters
[1 2 3] => (has-suffix   [3 2] :in-any-order) ; true
[1 2 3] => (has-suffix  #{3 2}) ; true 
sourceraw docstring

irrelevantclj

(irrelevant actual)

Accepts any value.

Accepts any value.
sourceraw docstring

justclj

(just expected)
(just expected looseness)

A variant of contains, just, will fail if the left-hand-side contains any extra values: [1 2 3] => (just [1 2 3]) ; true [1 2 3] => (just [1 2 3 4]) ; false

The first of those seems senseless, since you could just use this:

[1 2 3] => [1 2 3]

However, it's required if you want to use checkers in the expected result:

[1 2 3] => [odd? even? odd?] ; false b/c 2nd-level fns aren't normally treated as checkers. [1 2 3] => (just [odd? even? odd?]) ; true

just is also useful if you don't care about order:

[1 3 2] => (just [1 2 3] :in-any-order) [1 3 2] => (just #{1 2 3})

A variant of contains, just, will fail if the
left-hand-side contains any extra values:
   [1 2 3] => (just [1 2 3])  ; true
   [1 2 3] => (just [1 2 3 4]) ; false

The first of those seems senseless, since you could just use this:

   [1 2 3] => [1 2 3]

However, it's required if you want to use checkers in the expected result:

   [1 2 3] => [odd? even? odd?]  ; false b/c 2nd-level fns aren't normally treated as checkers.
   [1 2 3] => (just [odd? even? odd?]) ; true

just is also useful if you don't care about order:

  [1 3 2] => (just   [1 2 3] :in-any-order)
  [1 3 2] => (just  #{1 2 3})
sourceraw docstring

n-ofclj

(n-of expected expected-count)

Checks whether a sequence contains precisely n results, and that they each match the checker.

Ex. (fact (repeat 100 :a) => (n-of :a 100))

Checks whether a sequence contains precisely n results, and
 that they each match the checker.

Ex. (fact (repeat 100 :a) => (n-of :a 100))
sourceraw docstring

nine-ofclj

(nine-of expected)

Checks whether a sequence contains precisely nine results, and that they each match the checker.

Ex. (fact [:a :a :a :a :a :a :a :a :a] => (nine-of :a))

Checks whether a sequence contains precisely nine results, and 
that they each match the checker.

 Ex. (fact [:a :a :a :a :a :a :a :a :a] => (nine-of :a))
sourceraw docstring

one-ofclj

(one-of expected)

Checks whether a sequence contains precisely one result, and that it matches the checker.

Ex. (fact [:a] => (one-of :a))

Checks whether a sequence contains precisely one result, and 
that it matches the checker.

 Ex. (fact [:a] => (one-of :a))
sourceraw docstring

roughlyclj

(roughly expected)
(roughly expected delta)

With two arguments, accepts a value within delta of the expected value. With one argument, the delta is 1/1000th of the expected value.

With two arguments, accepts a value within delta of the
expected value. With one argument, the delta is 1/1000th
of the expected value.
sourceraw docstring

seven-ofclj

(seven-of expected)

Checks whether a sequence contains precisely seven results, and that they each match the checker.

Ex. (fact [:a :a :a :a :a :a :a] => (seven-of :a))

Checks whether a sequence contains precisely seven results, and 
that they each match the checker.

 Ex. (fact [:a :a :a :a :a :a :a] => (seven-of :a))
sourceraw docstring

six-ofclj

(six-of expected)

Checks whether a sequence contains precisely six results, and that they each match the checker.

Ex. (fact [:a :a :a :a :a :a] => (six-of :a))

Checks whether a sequence contains precisely six results, and 
that they each match the checker.

 Ex. (fact [:a :a :a :a :a :a] => (six-of :a))
sourceraw docstring

some-checkercljmacro

(some-checker & checker-forms)

Combines multiple checkers into one checker that passes when any of the component checkers pass. If one checker passes, the remainder are not run. Example:

(fact 3 => (some-checker even? neg?)) ; fails

The combined checkers can include anything that can appear on the right-hand side of an arrow.

Example:

(fact "-1b-" => (some-checker #(= 4 (count %))
                              "-1b-"))
Combines multiple checkers into one checker that passes
when any of the component checkers pass. If one checker
passes, the remainder are not run. Example:

   (fact 3 => (some-checker even? neg?)) ; fails

The combined checkers can include anything that can appear on the
right-hand side of an arrow.

Example:

    (fact "-1b-" => (some-checker #(= 4 (count %))
                                  "-1b-"))
sourceraw docstring

ten-ofclj

(ten-of expected)

Checks whether a sequence contains precisely ten results, and that they each match the checker.

Ex. (fact [:a :a :a :a :a :a :a :a :a :a] => (ten-of :a))

Checks whether a sequence contains precisely ten results, and 
that they each match the checker.

 Ex. (fact [:a :a :a :a :a :a :a :a :a :a] => (ten-of :a))
sourceraw docstring

three-ofclj

(three-of expected)

Checks whether a sequence contains precisely three results, and that they each match the checker.

Ex. (fact [:a :a :a] => (three-of :a))

Checks whether a sequence contains precisely three results, and 
that they each match the checker.

 Ex. (fact [:a :a :a] => (three-of :a))
sourceraw docstring

throwsclj

(throws & desiderata)

Checks for a thrown Throwable.

The most common cases are: (fact (foo) => (throws IOException) (fact (foo) => (throws IOException #"No such file")

throws takes three kinds of arguments:

  • A class argument requires that the Throwable be of that class.
  • A string or regular expression requires that the message of the Throwable match the argument.
  • A function argument requires that the function, when applied to the Throwable, return a truthy value.

Arguments can be in any order. Except for a class argument, they can be repeated. So, for example, you can write this: (fact (foo) => (throws #"one part" #"another part"))

Checks for a thrown Throwable.

The most common cases are:
    (fact (foo) => (throws IOException)
    (fact (foo) => (throws IOException #"No such file")

`throws` takes three kinds of arguments:
* A class argument requires that the Throwable be of that class.
* A string or regular expression requires that the `message` of the Throwable
  match the argument.
* A function argument requires that the function, when applied to the Throwable,
  return a truthy value.

Arguments can be in any order. Except for a class argument, they can be repeated.
So, for example, you can write this:
    (fact (foo) => (throws #"one part" #"another part"))
sourceraw docstring

TRUTHYclj

(TRUTHY actual)

Returns precisely true if actual is not nil and not false.

Returns precisely true if actual is not nil and not false.
sourceraw docstring

truthyclj

(truthy actual)

Returns precisely true if actual is not nil and not false.

Returns precisely true if actual is not nil and not false.
sourceraw docstring

two-ofclj

(two-of expected)

Checks whether a sequence contains precisely two results, and that they each match the checker.

Ex. (fact [:a :a] => (two-of :a))

Checks whether a sequence contains precisely two results, and 
that they each match the checker.

 Ex. (fact [:a :a] => (two-of :a))
sourceraw docstring

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

× close