Functions useful when using Midje in the repl or from the command line.
See midje-repl-help
for details.
Functions useful when using Midje in the repl or from the command line. See `midje-repl-help` for details.
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.
Stores last exception encountered in autotesting
Stores last exception encountered in autotesting
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"))
(autotest & args)
autotest
checks frequently for changed files. It reloads those files
and all files that depend on them. Since test files depend on source files,
that typically results in facts being reloaded and checked.
By default, autotest
monitors all the files in the
project.clj's :source-paths and :test-paths. To change the
default, give the :files
argument:
(autotest :files "test/midje/util" "src/midje/util") (autotest :files "test/midje/util/t_unify.clj" "src/midje/util/unify.clj")
This is useful in large projects. Note that autotest
doesn't follow
dependencies outside the given directories. If test/midje/util/A
depends on some-untracked-dir/B
that depends on src/midje/util/C
,
a change to C
will not cause A
to be reloaded.
You can revert back to the project.clj versions like this:
(autotest :all)
You can filter the facts checked by giving more arguments following
a :filter
or :filters
keyword:
(autotest :filter :integration)
Facts matching any of the arguments are the ones that are checked. The arguments can be of these types:
:keyword -- Does the metadata have a truthy value for the keyword? "string" -- Does the fact's name contain the given string? #"regex" -- Does any part of the fact's name match the regex? a function -- Does the function return a truthy value when given the fact's metadata?
autotest
can take special keyword arguments:
(autotest :stop) ; stop checking (autotest :pause) ; pause checking (autotest :resume) ; continue after a pause
autotest
can also be given an :interval
argument to control how often
it checks for modified files. The argument is in milliseconds:
(autotest :interval 1000) ; check each second.
The default is to check twice each second.
`autotest` checks frequently for changed files. It reloads those files and all files that depend on them. Since test files depend on source files, that typically results in facts being reloaded and checked. By default, `autotest` monitors all the files in the project.clj's :source-paths and :test-paths. To change the default, give the `:files` argument: (autotest :files "test/midje/util" "src/midje/util") (autotest :files "test/midje/util/t_unify.clj" "src/midje/util/unify.clj") This is useful in large projects. Note that `autotest` doesn't follow dependencies outside the given directories. If `test/midje/util/A` depends on `some-untracked-dir/B` that depends on `src/midje/util/C`, a change to `C` will not cause `A` to be reloaded. You can revert back to the project.clj versions like this: (autotest :all) You can filter the facts checked by giving more arguments following a `:filter` or `:filters` keyword: (autotest :filter :integration) Facts matching any of the arguments are the ones that are checked. The arguments can be of these types: :keyword -- Does the metadata have a truthy value for the keyword? "string" -- Does the fact's name contain the given string? #"regex" -- Does any part of the fact's name match the regex? a function -- Does the function return a truthy value when given the fact's metadata? `autotest` can take special keyword arguments: (autotest :stop) ; stop checking (autotest :pause) ; pause checking (autotest :resume) ; continue after a pause `autotest` can also be given an `:interval` argument to control how often it checks for modified files. The argument is in milliseconds: (autotest :interval 1000) ; check each second. The default is to check twice each second.
(autotest-default-dirs)
These are the directories that will be watched if you type
autotest
with no arguments.
These are the directories that will be watched if you type `autotest` with no arguments.
(autotest-options)
If you want a peek at how autotest is controlled, look here.
If you want a peek at how autotest is controlled, look here.
(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`.
(check-facts & args__11281__auto__)
Check facts that have already been defined.
(check-facts ns midje.t-repl) -- defined in named namespaces (check-facts :all) -- defined anywhere (check-facts) -- check same facts again
You can further filter the facts by giving more arguments. Facts matching any of the arguments are the ones that are checked. The arguments are:
:keyword -- Does the metadata have a truthy value for the keyword? "string" -- Does the fact's name contain the given string? #"regex" -- Does any part of the fact's name match the regex? a function -- Does the function return a truthy value when given the fact's metadata?
In addition, you can adjust what's printed. See (doc midje-print-levels)
.
If the call doesn't mention any namespaces, the ones from the
previous load-facts
, check-facts
, or fetch-facts
are
reused. The filters and print-levels are also reused, unless
they're overridden with explicit arguments.
Check facts that have already been defined. (check-facts *ns* midje.t-repl) -- defined in named namespaces (check-facts :all) -- defined anywhere (check-facts) -- check same facts again You can further filter the facts by giving more arguments. Facts matching any of the arguments are the ones that are checked. The arguments are: :keyword -- Does the metadata have a truthy value for the keyword? "string" -- Does the fact's name contain the given string? #"regex" -- Does any part of the fact's name match the regex? a function -- Does the function return a truthy value when given the fact's metadata? In addition, you can adjust what's printed. See `(doc midje-print-levels)`. If the call doesn't mention any namespaces, the ones from the previous `load-facts`, `check-facts`, or `fetch-facts` are reused. The filters and print-levels are also reused, unless they're overridden with explicit arguments.
Check a single fact. Takes as its argument a function such
as is returned by last-fact-checked
.
Check a single fact. Takes as its argument a function such as is returned by `last-fact-checked`.
(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-description fact)
Return the description of the given fact.
Facts are in the form returned by fetch-facts
.
Return the description of the given fact. Facts are in the form returned by `fetch-facts`.
(fact-file fact)
Return the file of the given fact.
Facts are in the form returned by fetch-facts
.
Return the file of the given fact. Facts are in the form returned by `fetch-facts`.
(fact-group & forms)
Supply default metadata to all facts in the body.
Supply default metadata to all facts in the body.
(fact-guid fact)
Return the guid of the given fact.
Facts are in the form returned by fetch-facts
.
Return the guid of the given fact. Facts are in the form returned by `fetch-facts`.
(fact-line fact)
Return the line of the given fact.
Facts are in the form returned by fetch-facts
.
Return the line of the given fact. Facts are in the form returned by `fetch-facts`.
(fact-name fact)
Return the name of the given fact.
Facts are in the form returned by fetch-facts
.
Return the name of the given fact. Facts are in the form returned by `fetch-facts`.
(fact-namespace fact)
Return the namespace of the given fact.
Facts are in the form returned by fetch-facts
.
Return the namespace of the given fact. Facts are in the form returned by `fetch-facts`.
(fact-source fact)
Return the source of the given fact.
Facts are in the form returned by fetch-facts
.
Return the source of the given fact. Facts are in the form returned by `fetch-facts`.
(fact-top-level? fact)
Return the top-level? of the given fact.
Facts are in the form returned by fetch-facts
.
Return the top-level? of the given fact. Facts are in the form returned by `fetch-facts`.
(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.
(fetch-facts & args__11281__auto__)
Fetch facts that have already been defined, whether by loading them from a file or via the repl.
(fetch-facts ns 'midje.t-repl) -- facts defined in these namespaces (fetch-facts :all) -- all known facts (fetch-facts) -- reuse previous arguments
You can further filter the facts by giving more arguments. Facts matching any of the arguments are included in the result. The arguments are:
:keyword -- Does the metadata have a truthy value for the keyword? "string" -- Does the fact's name contain the given string? #"regex" -- Does any part of the fact's name match the regex? a function -- Does the function return a truthy value when given the fact's metadata?
If the call doesn't mention any namespaces, the ones from the
previous load-facts
, check-facts
, or fetch-facts
are
reused. The filters are also reused, unless they're overridden
with explicit arguments.
Fetch facts that have already been defined, whether by loading them from a file or via the repl. (fetch-facts *ns* 'midje.t-repl) -- facts defined in these namespaces (fetch-facts :all) -- all known facts (fetch-facts) -- reuse previous arguments You can further filter the facts by giving more arguments. Facts matching any of the arguments are included in the result. The arguments are: :keyword -- Does the metadata have a truthy value for the keyword? "string" -- Does the fact's name contain the given string? #"regex" -- Does any part of the fact's name match the regex? a function -- Does the function return a truthy value when given the fact's metadata? If the call doesn't mention any namespaces, the ones from the previous `load-facts`, `check-facts`, or `fetch-facts` are reused. The filters are also reused, unless they're overridden with explicit arguments.
(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))
(forget-facts & args__11281__auto__)
Forget defined facts so that they will not be found by check-facts
or fetch-facts
.
(forget-facts ns midje.t-repl -- defined in named namespaces
(forget-facts :all) -- defined anywhere
(forget-facts) -- forget facts worked on by most
recent check-facts
, load-facts
,
or fetch-facts
.
You can further filter the facts by giving more arguments. Facts matching any of the arguments are the ones that are forgotten. The arguments are:
:keyword -- Does the metadata have a truthy value for the keyword? "string" -- Does the fact's name contain the given string? #"regex" -- Does any part of the fact's name match the regex? a function -- Does the function return a truthy value when given the fact's metadata?
Filters from the previous command are reused unless they're overridden.
Forget defined facts so that they will not be found by `check-facts` or `fetch-facts`. (forget-facts *ns* midje.t-repl -- defined in named namespaces (forget-facts :all) -- defined anywhere (forget-facts) -- forget facts worked on by most recent `check-facts`, `load-facts`, or `fetch-facts`. You can further filter the facts by giving more arguments. Facts matching any of the arguments are the ones that are forgotten. The arguments are: :keyword -- Does the metadata have a truthy value for the keyword? "string" -- Does the fact's name contain the given string? #"regex" -- Does any part of the fact's name match the regex? a function -- Does the function return a truthy value when given the fact's metadata? Filters from the previous command are reused unless they're overridden.
(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})
(last-fact-checked)
The last fact or tabular fact that was checked. Only top-level facts are recorded, not facts nested within them.
The last fact or tabular fact that was checked. Only top-level facts are recorded, not facts nested within them.
(load-facts & args__11281__auto__)
Load given namespaces, as in: (load-facts 'midje.t-sweet 'midje.t-repl)
A partial namespace ending in a *
will load all sub-namespaces.
Example: (load-facts 'midje.ideas.*)
If the :all argument is given, all the namespaces in the project.clj's :test-paths and :source-paths will be loaded. But if there's no project.clj, all namespaces under "test" will be loaded.
By default, all facts are loaded from the namespaces. You can, however, add further arguments. Only facts matching one or more of the arguments are loaded. The filter arguments are:
:keyword -- Does the metadata have a truthy value for the keyword? "string" -- Does the fact's name contain the given string? #"regex" -- Does any part of the fact's name match the regex? a function -- Does the function return a truthy value when given the fact's metadata?
In addition, you can adjust what's printed during loading.
See (doc midje-print-levels)
.
If the call doesn't mention any namespaces, the ones from
the previous load-facts
are reused. The filters and print-levels
are also reused, unless they're overridden with explicit arguments.
Load given namespaces, as in: (load-facts 'midje.t-sweet 'midje.t-repl) A partial namespace ending in a `*` will load all sub-namespaces. Example: (load-facts 'midje.ideas.*) If the :all argument is given, all the namespaces in the project.clj's :test-paths and :source-paths will be loaded. But if there's no project.clj, all namespaces under "test" will be loaded. By default, all facts are loaded from the namespaces. You can, however, add further arguments. Only facts matching one or more of the arguments are loaded. The filter arguments are: :keyword -- Does the metadata have a truthy value for the keyword? "string" -- Does the fact's name contain the given string? #"regex" -- Does any part of the fact's name match the regex? a function -- Does the function return a truthy value when given the fact's metadata? In addition, you can adjust what's printed during loading. See `(doc midje-print-levels)`. If the call doesn't mention any namespaces, the ones from the previous `load-facts` are reused. The filters and print-levels are also reused, unless they're overridden with explicit arguments.
(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
(recheck-fact)
(recheck-fact print-level)
Recheck the last fact or tabular fact that was checked. When facts are nested, the entire outer-level fact is rechecked. The result is true if the fact checks out.
The optional argument lets you adjust what's printed.
See (print-level-help)
for legal values.
Recheck the last fact or tabular fact that was checked. When facts are nested, the entire outer-level fact is rechecked. The result is true if the fact checks out. The optional argument lets you adjust what's printed. See `(print-level-help)` for legal values.
(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.
(set-autotest-option! key value)
Set autotest options without starting autotesting.
Set autotest options without starting autotesting.
(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-"))
(source-of-last-fact-checked)
Returns the source of the last fact or tabular fact run.
Returns the source of the last fact or tabular fact run.
(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