-
Notifications
You must be signed in to change notification settings - Fork 58
Spec components
Micah Martin edited this page Mar 10, 2015
·
8 revisions
DEPRECATED
See API Documentation instead.
Below is a listing of all the "spec components" allowed in a describe
. But first let's define describe
.
Declares a new spec. The body can contain any forms that evaluate to spec components (it, before, after, with ...).
(describe "Calculator"
... ; spec components
)
(it "adds numbers"
(should= 2 (+ 1 1)))
(before (println "A spec is about to be evaluated"))
(after (println "A spec has just been evaluated"))
(before-all (println "May the spec'ing begin!"))
(after-all (println "That's all folks."))
(with nice-format (java.text.DecimalFormat. "0.00000"))
(it "formats numbers nicely"
(should= "3.14159" (.format @nice-format Math/PI)))
(declare *the-answer*) ; outside of a describe
(around [it]
(binding [*the-answer* 42]
(it)))
(it "knows the answer"
(should= 42 *the-answer*))
With all the above components in use like so...
(ns basics-spec
(:use [speclj.core]))
(declare *the-answer*)
(describe "Calculator"
(before (println "A spec is about to be evaluated"))
(after (println "A spec has just been evaluated"))
(before-all (println "May the spec'ing begin!"))
(after-all (println "That's all folks."))
(with nice-format (java.text.DecimalFormat. "0.00000"))
(around [it]
(binding [*the-answer* 42]
(it)))
(it "adds numbers"
(should= 2 (+ 1 1)))
(it "formats numbers nicely"
(should= "3.14159" (.format @nice-format Math/PI)))
(it "knows the answer"
(should= 42 *the-answer*))
)
(run-specs)
We get the following output:
May the spec'ing begin!
A spec is about to be evaluated
A spec has just been evaluated
.A spec is about to be evaluated
A spec has just been evaluated
.A spec is about to be evaluated
A spec has just been evaluated
.That's all folks.
Finished in 0.00377 seconds
3 examples, 0 failures