A TDD library for Clojure that supports top-down ('mockish') TDD, encourages readable tests, provides a smooth migration path from clojure.test, balances abstraction and concreteness, and strives for graciousness.
A TDD library for Clojure that supports top-down ('mockish') TDD, encourages readable tests, provides a smooth migration path from clojure.test, balances abstraction and concreteness, and strives for graciousness.
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.
This variable is defunct. Use include-midje-checks
instead.
This variable is defunct. Use `include-midje-checks` instead.
As a checking arrow: the left side should result in the right side. As a prerequisite arrow: the fake should return the thing on the right.
As a checking arrow: the left side should result in the right side. As a prerequisite arrow: the fake should return the thing on the right.
Data prerequisite arrow. Ex. (fact (:a ..m..) => 1 (provided ..m.. =contains=> {:a 1}))
Data prerequisite arrow. Ex. (fact (:a ..m..) => 1 (provided ..m.. =contains=> {:a 1}))
Checking arrow. The left side should NOT result in the right side.
Checking arrow. The left side should NOT result in the right side.
Checking arrow. The left side should macroexpand-1 to the right side.
Checking arrow. The left side should macroexpand-1 to the right side.
Checking arrow. The check won't evaluate, but will leave a 'WORK TO DO' reminder in the report.
Checking arrow. The check won't evaluate, but will leave a 'WORK TO DO' reminder in the report.
Checking arrow. The left side should NOT result in the right side.
Checking arrow. The left side should NOT result in the right side.
Prerequisite arrow. The fake will return the first element of the given sequence the first time the fake is evaluated, the second element the second time, and so on. Note, that each element is only evaluated when needed, thus in the below example the exception is never thrown.
Ex. (def tally [] (+ (bar) (bar) (bar))) (fact (tally) => 6 (provided (bar) =streams=> [1 2 3 (throw (Exception.))]))
Prerequisite arrow. The fake will return the first element of the given sequence the first time the fake is evaluated, the second element the second time, and so on. Note, that each element is only evaluated when needed, thus in the below example the exception is never thrown. Ex. (def tally [] (+ (bar) (bar) (bar))) (fact (tally) => 6 (provided (bar) =streams=> [1 2 3 (throw (Exception.))]))
Use this when testing Midje code that processes arrow-forms
Use this when testing Midje code that processes arrow-forms
Use this to generate an exception while parsing
Use this to generate an exception while parsing
Prerequisite arrow. The fake will throw the Throwable on the right side of the arrow.
Ex. (def f [] (g)) (fact (f) => (throws IllegalArgumentException. "boom") (provided (g) =throws=> (IllegalArgumentException. "boom")))
Prerequisite arrow. The fake will throw the Throwable on the right side of the arrow. Ex. (def f [] (g)) (fact (f) => (throws IllegalArgumentException. "boom") (provided (g) =throws=> (IllegalArgumentException. "boom")))
(add-midje-fact-symbols symbols)
If you use a macro to wrap Midje's fact forms, with-state-changes
will
complain that it contains no facts. You can avoid that by "registering"
your macro with Midje.
If you use a macro to wrap Midje's fact forms, `with-state-changes` will complain that it contains no facts. You can avoid that by "registering" your macro with Midje.
(after _wrapping-target_ after-form)
Code to run after a given wrapping target (:facts, :contents, :checks). Used with background and against-background
Code to run after a given wrapping target (:facts, :contents, :checks). Used with background and against-background
(against-background background-forms & foreground-forms)
Puts a series of background changers into effect until the end
of the against-background
scope. They remain in effect when a
loaded fact is rechecked (as with midje.repl/recheck-fact
).
See (doc midje-background-changers)
for details on background
changers.
against-background
can be used in two ways. In the first, it has
a let
-like syntax that wraps a series of facts:
(against-background [(f 33) => 12 (f 34) => 21 (before :facts (reset! some-atom 0))] (fact...) (fact...))
In the second, it can be placed as either the first or last form in a fact, in which case it is taken to "wrap" the entire fact:
(against-background (f 1) => :default, (g 1) => :default)
Note that in this case the square brackets can be omitted.
Puts a series of *background changers* into effect until the end of the `against-background` scope. They remain in effect when a loaded fact is rechecked (as with `midje.repl/recheck-fact`). See `(doc midje-background-changers)` for details on background changers. `against-background` can be used in two ways. In the first, it has a `let`-like syntax that wraps a series of facts: (against-background [(f 33) => 12 (f 34) => 21 (before :facts (reset! some-atom 0))] (fact...) (fact...)) In the second, it can be placed as either the first or last form in a fact, in which case it is taken to "wrap" the entire fact: (against-background (f 1) => :default, (g 1) => :default) Note that in this case the square brackets can be omitted.
(antiterminologicaldisintactitudinarian-fact
&
midje.parsing.util.future-variants/forms)
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
(antiterminologicaldisintactitudinarian-facts
&
midje.parsing.util.future-variants/forms)
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
(antiterminologicaldisintactitudinarian-formula
&
midje.parsing.util.future-variants/forms)
ALPHA/EXPERIMENTAL (subject to change) Formula that will not be run. Generates 'WORK TO DO' report output as a reminder.
ALPHA/EXPERIMENTAL (subject to change) Formula that will not be run. Generates 'WORK TO DO' report output as a reminder.
(around _wrapping-target_ around-form)
Code to run around a given wrapping target (:facts, :contents, :checks). Use the symbol '?form' to denote the code that is being wrapped around.
Ex. (around :contents (let [a 999] ?form (print a)))
Used with background and against-background
Code to run around a given wrapping target (:facts, :contents, :checks). Use the symbol '?form' to denote the code that is being wrapped around. Ex. (around :contents (let [a 999] ?form (print a))) Used with background and against-background
(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"))
(background & background-changers)
Puts a series of background changers into effect from the point of
execution until the end of the file. They are also in effect when
a loaded fact is rechecked (as with midje.repl/recheck-fact
).
See (doc midje-background-changers)
for details on background
changers.
Examples:
(background (f 33) => 12, (f 34) => 21) (background (before :facts (reset! some-atom 0)))
Puts a series of *background changers* into effect from the point of execution until the end of the file. They are also in effect when a loaded fact is rechecked (as with `midje.repl/recheck-fact`). See `(doc midje-background-changers)` for details on background changers. Examples: (background (f 33) => 12, (f 34) => 21) (background (before :facts (reset! some-atom 0)))
(before _wrapping-target_ before-form & {:keys [after]})
Code to run before a given wrapping target (:facts, :contents, :checks). Can take an optional keyword argument :after, for any code to run afterward. Used with background and against-background
Code to run before a given wrapping target (:facts, :contents, :checks). Can take an optional keyword argument :after, for any code to run afterward. Used with background and against-background
(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`.
(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)
(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.)
(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)`.
(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))
(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"))
(exactly expected)
Checks for equality. Use to avoid default handling of functions.
Checks for equality. Use to avoid default handling of functions.
(fact & _)
A fact is a statement about code:
(fact "one plus one is two" (+ 1 1) => 2)
Facts may describe one functions dependency on another:
(fact (f ..x..) => 12 (provided (g ..x..) => 6))
A fact is a statement about code: (fact "one plus one is two" (+ 1 1) => 2) Facts may describe one functions dependency on another: (fact (f ..x..) => 12 (provided (g ..x..) => 6))
(fact-group & forms)
Supply default metadata to all facts in the body.
Supply default metadata to all facts in the body.
(FALSEY actual)
Returns precisely true if actual is nil or false.
Returns precisely true if actual is nil or false.
(falsey actual)
Returns precisely true if actual is nil or false.
Returns precisely true if actual is nil or false.
(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))
(formula docstring? opts-map? bindings & body)
Generative-style fact macro.
Ex. (formula "any two strings concatenated begins with the first" [a (gen/string) b (gen/string)] (str a b) => (has-prefix a))
Currently, we recommend you use generators from test.generative.generators.
opts-map keys:
:num-trials - Used to override the number of trials for this formula only. This is higher precedence than num-trials Must be set to a number 1 or greater.
The num-trials dynamic var determines how many facts are generated per formula.
Generative-style fact macro. Ex. (formula "any two strings concatenated begins with the first" [a (gen/string) b (gen/string)] (str a b) => (has-prefix a)) Currently, we recommend you use generators from test.generative.generators. opts-map keys: :num-trials - Used to override the number of trials for this formula only. This is higher precedence than *num-trials* Must be set to a number 1 or greater. The *num-trials* dynamic var determines how many facts are generated per formula.
(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))
(future-fact & midje.parsing.util.future-variants/forms)
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
(future-facts & midje.parsing.util.future-variants/forms)
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
(future-formula & midje.parsing.util.future-variants/forms)
ALPHA/EXPERIMENTAL (subject to change) Formula that will not be run. Generates 'WORK TO DO' report output as a reminder.
ALPHA/EXPERIMENTAL (subject to change) Formula that will not be run. Generates 'WORK TO DO' report output as a reminder.
(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?))
(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
(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
(incipient-fact & midje.parsing.util.future-variants/forms)
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
(incipient-facts & midje.parsing.util.future-variants/forms)
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
(incipient-formula & midje.parsing.util.future-variants/forms)
ALPHA/EXPERIMENTAL (subject to change) Formula that will not be run. Generates 'WORK TO DO' report output as a reminder.
ALPHA/EXPERIMENTAL (subject to change) Formula that will not be run. Generates 'WORK TO DO' report output as a reminder.
True by default. If set to false, Midje checks are not included into production code, whether compiled or loaded.
Note that the variable must be set, as with alter-var-root
or def
, not bound, as with binding
.
True by default. If set to false, Midje checks are not included into production code, whether compiled or loaded. Note that the variable must be set, as with `alter-var-root` or `def`, not bound, as with `binding`.
(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})
(metaconstants & symbols)
For a few operations, such as printing and equality checking, the Clojure AOT-compiler becomes confused by Midje's auto-generation of metaconstants. If AOT-compiled tests fail when on-the-fly compiled tests failed, declare your metaconstants before use. Example: (metaconstants ..m.. ..m.... .mc.)
For a few operations, such as printing and equality checking, the Clojure AOT-compiler becomes confused by Midje's auto-generation of metaconstants. If AOT-compiled tests fail when on-the-fly compiled tests failed, declare your metaconstants before use. Example: (metaconstants ..m.. ..m.... .mc.)
(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))
(namespace-state-changes & instructions)
Applies arguments to any facts later created in the namespace. Often used in the repl. Example:
(namespace-state-changes (before :facts (reset! state 0))
(after :facts (reset! state 1111)))
A later use of namespace-state-changes
replaces the effect of an earlier
one. To "turn off" a previous use, do this:
(namespace-state-changes)
Applies arguments to any facts later created in the namespace. Often used in the repl. Example: (namespace-state-changes (before :facts (reset! state 0)) (after :facts (reset! state 1111))) A later use of `namespace-state-changes` replaces the effect of an earlier one. To "turn off" a previous use, do this: (namespace-state-changes)
(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))
(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))
(pending-fact & midje.parsing.util.future-variants/forms)
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
(pending-facts & midje.parsing.util.future-variants/forms)
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
Fact that will not be run. Generates 'WORK TO DO' report output as a reminder.
(pending-formula & midje.parsing.util.future-variants/forms)
ALPHA/EXPERIMENTAL (subject to change) Formula that will not be run. Generates 'WORK TO DO' report output as a reminder.
ALPHA/EXPERIMENTAL (subject to change) Formula that will not be run. Generates 'WORK TO DO' report output as a reminder.
A declaration of the provided form
A declaration of the provided form
(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.
(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))
(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))
(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-"))
(tabular doc-string? fact table)
Generate a table of related facts.
Ex. (tabular "table of simple math" (fact (+ ?a ?b) => ?c)
?a ?b ?c
1 2 3
3 4 7
9 10 19 )
Generate a table of related facts. Ex. (tabular "table of simple math" (fact (+ ?a ?b) => ?c) ?a ?b ?c 1 2 3 3 4 7 9 10 19 )
(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))
(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))
(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:
message
of the Throwable
match the argument.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"))
(TRUTHY actual)
Returns precisely true if actual is not nil and not false.
Returns precisely true if actual is not nil and not false.
(truthy actual)
Returns precisely true if actual is not nil and not false.
Returns precisely true if actual is not nil and not false.
(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))
(unfinished & names)
Defines a list of names as functions that have no implementation yet. They will throw Errors if ever called.
Defines a list of names as functions that have no implementation yet. They will throw Errors if ever called.
(with-state-changes & forms)
Describe how state should change before or after enclosed facts. Example:
(with-state-changes [(before :facts (reset! state 0)) (after :facts (reset! state 1111))] (fact ...) (fact ...))
Describe how state should change before or after enclosed facts. Example: (with-state-changes [(before :facts (reset! state 0)) (after :facts (reset! state 1111))] (fact ...) (fact ...))
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close