-
Notifications
You must be signed in to change notification settings - Fork 58
Should variants
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
- should-not-be
- should
- should-not
- should=
- should-not=
- should==
- should-not==
- should-contain
- should-not-contain
- should-fail
- should-throw
- should-not-throw
(should-be empty? []) ; passes
(should-be empty? [1 2 3]) ; fails
(should-not-be empty? []) ; fails
(should-not-be empty? [1 2 3]) ; passes
(should true) ; passes
(should false) ; fails
(should-not true) ; fails
(should-not false) ; passes
(should= 1 1) ; passes
(should= 1 2) ; fails
(should-not= 1 1) ; fails
(should-not= 1 2) ; passes
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
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 "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-fail) ; fails
(should-fail "my message") ; fails and "my message" is used as failure message
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 (+ 1 1)) ; passes
(should-not-throw (Exception.)) ; fails