Skip to content
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.

describe

Declares a new spec. The body can contain any forms that evaluate to spec components (it, before, after, with ...).

 (describe "Calculator"
   ... ; spec components
   )

Spec Components

it

Declares a new characteristic (example in rspec). The first parameter `name` should be a string the describes the characteristic. The second parameter `body` may be any forms but aught to have at least one `should` assertion.
 (it "adds numbers"
   (should= 2 (+ 1 1)))

before

Declares a function that is invoked before each characteristic in the containing describe scope is evaluated. The body may consist of any forms, presumably ones that perform side effects.
 (before (println "A spec is about to be evaluated"))

after

Declares a function that is invoked after each characteristic in the containing describe scope is evaluated. The body may consist of any forms, presumably ones that perform side effects.
 (after (println "A spec has just been evaluated"))

before-all

Declares a function that is invoked once before any characteristic in the containing describe scope is evaluated. The body may consist of any forms, presumably ones that perform side effects.
 (before-all (println "May the spec'ing begin!"))

after-all

Declares a function that is invoked once after all the characteristics in the containing describe scope have been evaluated. The body may consist of any forms, presumably ones that perform side effects.
 (after-all (println "That's all folks."))

with

Declares a reference-able symbol that will be lazily evaluated once per characteristic of the containing describe scope. The body may contain any forms, the last of which will be the value of the dereferenced symbol.
 (with nice-format (java.text.DecimalFormat. "0.00000"))

 (it "formats numbers nicely"
   (should= "3.14159" (.format @nice-format Math/PI)))

around

Declares a function that will be invoked around each characteristic of the containing describe scope. The characteristic will be passed in and the around function is responsible for invoking it.
 (declare *the-answer*) ; outside of a describe

 (around [it]
   (binding [*the-answer* 42]
     (it)))

 (it "knows the answer"
   (should= 42 *the-answer*))

All Together Now

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