Rack  Unit Spec:   BDD interface for Rack  Unit
describe
context
it
7.1

RackUnit Spec: BDD interface for RackUnit

Alexis King <[email protected]>

 (require rackunit/spec) package: rackunit-spec

This library implements forms to assist with writing tests using the style associated with behavior-driven development on top of rackunit.

Examples:
> (describe "add1"
    (context "given a number"
      (it "increments it by one"
        (check-equal? (add1 0) 1)
        (check-equal? (add1 -5) -4)
        (check-equal? (add1 41) 42)))
  
    (context "given a non-number"
      (it "throws an exception"
        (check-exn exn:fail:contract?
                   (thunk (add1 "hello"))))))
> (define (broken-fibonacci n)
    (cond [(= n 0) 0]
          [(= n 1) 1]
          [else    (+ (broken-fibonacci (- n 1))
                      (broken-fibonacci (- n 1)))]))
> (describe "broken-fibonacci"
    (context "given a positive integer"
      (it "returns the nth fibonacci number"
        (check-equal? (broken-fibonacci 6) 8))))

--------------------

broken-fibonacci

  given a positive integer

    returns the nth fibonacci number

FAILURE

name:       check-equal?

location:   eval:3:0

actual:     32

expected:   8

--------------------

syntax

(describe description-str body-expr ...+)

syntax

(context description-str body-expr ...+)

Used to annotate groups of tests contained within it blocks. The describe and context forms are identical in behavior, but the context form can be used to more clearly specify that the description refers to a particular condition rather than a form or function being described.

syntax

(it description-str body-expr ...+)

Like test-case from rackunit, but the description is augmented with information from the enclosing describe and context forms.