Skip to content
Micah Martin edited this page Mar 10, 2015 · 29 revisions

DEPRECATED

See API Documentation instead.


Below is a listing of all the variety of should assertions.

## should-be Asserts that a form satisfies a function
(should-be empty? []) ; passes
(should-be empty? [1 2 3]) ; fails
## should-not-be Asserts that a form does not satisfy a function
(should-not-be empty? []) ; fails
(should-not-be empty? [1 2 3]) ; passes
## should Asserts the truthy-ness of a form
(should true) ; passes
(should false) ; fails
## should-not Asserts the falsy-ness of a form
(should-not true) ; fails
(should-not false) ; passes
## should= Asserts that two forms evaluate to equal values, with the expected value as the first parameter.
(should= 1 1) ; passes
(should= 1 2) ; fails
## should-not= Asserts that two forms evaluate to inequal values, with the unexpected value as the first parameter.
(should-not= 1 1) ; fails
(should-not= 1 2) ; passes
## should== "Asserts 'equivalency'.

When passed collections it will check that they have the same contents.

For anything else it will assert that clojure.core/== returns true."

(should== 1 1.0) ; passes
(should== 1 2) ; fails
(should== [1 2] '(2 1)) ; passes
(should== [1 2] [3 4]) ; fails
(should== [1 2] [1 1 2]) ; fails
## should-not== "Asserts 'non-equivalency'.

When passed collections it will check that they do NOT have the same contents.

For anything else it will assert that clojure.core/== returns false."

(should-not== 1 1.0) ; fails
(should-not== 1 2) ; passes
(should-not== [1 2] '(2 1)) ; fails
(should-not== [1 2] [3 4]) ; passes
(should-not== [1 2] [1 1 2]) ; passes
## should-contain Multi-purpose assertion of containment. Works strings, regular expressions, sequences, and maps.
(should-contain "foo" "foobar")            ; looks for sub-string
(should-contain #"hello.*" "hello, world") ; looks for regular expression
(should-contain :foo {:foo :bar})          ; looks for a key in a map
(should-contain 3 [1 2 3 4])               ; looks for an object in a collection"
## should-not-contain Multi-purpose assertion of non-containment. See [should-contain](#should-contain) as an example of opposite behavior. ## should-fail Forces a failure. An optional message may be passed in.
(should-fail) ; fails
(should-fail "my message") ; fails and "my message" is used as failure message
## should-throw Asserts that a Throwable is thrown by the evaluation of a form.

When an class is passed, it asserts that the thrown Exception is an instance of the class.

When a string is also passed, it asserts that the message of the Exception is equal to the string.

(should-throw (+ 1 1)) ; fails
(should-throw (Exception.)) ; passes
(should-throw NullPointerException (Exception.)) ; fails
(should-throw Exception (NullPointerException.)) ; passes
(should-throw Exception "Foo" (Exception. "Bar")) ; fails
(should-throw Exception "Foo" (Exception. "Foo")) ; passes
## should-not-throw Asserts that nothing is thrown by the evaluation of a form.
(should-not-throw (+ 1 1)) ; passes
(should-not-throw (Exception.)) ; fails
Clone this wiki locally