You are looking at historical revision 23799 of this page. It may differ significantly from its current revision.



Missbehave is a toolkit that allows to you to bring behaviour driven development in the spirit of rspec, to your scheme of choice.

It is very much inspired and mostly modeled after the famous rspec-library.


(use missbehave miscmacros)

(define (callee . args) 'called)
(define (call-it n)
  (repeat n (callee)))

(describe "Missbehave features"
  (describe "implicit subject"
     (subject-set! 42)
     (it should (be 42))
     (it should (be a number)))
  (describe "Simple be matchers"
     (it "must be true"
         (expect #t (be true)))
     (it "must be a string"
         (expect "hello" to (be a string)))
     (it "can use standard operators"
         (expect 3 (be > 0)))
     (it "can use predicates"
         (expect '() (be null?))))

  (describe "Pending"
     (it "is implicitly pending")
     (it "is explicitly pending"
         (expect '() (be a number))))         

  (describe "Procedure expectations"
    (context "Application-count"
      (it "checks application count"
          (expect (call-it 1) to (call callee once)))
      (it "checks application count > 1"
          (expect (call-it 4) to (call callee (4 times))))
      (it "checks for no calls"
          (expect (+ 1 1) to (call callee never))))
    (context "Arguments"
     (it "checks arguments"
         (expect (callee 1 2) to (call callee (with 1 2))))
     (it "mixes arguments and application count"
         (expect (begin (callee 1 2) (callee 1 2)) to (call callee (with 1 2) twice)))))

  (describe "Procedure stubs"
    (it "can stub return values"
        (stub! callee (returns 'not-called))
        (expect (callee) to (be 'not-called)))

    (it "provides temporary stubs"
        (let ((proc (lambda () 'test)))
          (expect (proc) to (be 'test))
          (with-stubs! ((proc (returns 'passed)))
            (expect (proc) to (be 'passed)))
          (expect (proc) to (be 'test))))))

Now invoke it with:

$ behave test-spec.scm

Produces the following output:

Missbehave features
Procedure stubs
  It provides temporary stubs
  It can stub return values
Procedure expectations
  It mixes arguments and application count
  It checks arguments
  It checks for no calls
  It checks application count > 1
  It checks application count
  [P] It is explicitly pending
  [P] It is implicitly pending
Simple be matchers
  It can use predicates
  It can use standard operators
  It must be a string
  It must be true
implicit subject
  It should (be a number)
  It should (be 42)

Total: 15 Successful: 13 Pending: 2 Failures: 0



Contexts are a way to group your examples. You can use the the macro context and its alias describe to create them.

[syntax] (context context-name examples ...)

Create a context with the name context-name.

[syntax] (context context-name (meta (tags ...)) examples ...)

Create a context with name context-name and mark them with tags. This can be used to filter examples using the --tags command-line switch of behave.

[syntax] (context context-name (meta ((tag . value) ...) examples ...)

Create a context with name context-name and mark them with the key-value pairs. Those can be used to attach data and to filter them using the --tags command-line-switch of behave

(context "A simple context" 
  (it "does nothing"))

(context "A context with tags" (meta (long-running verbose))
  (it "is pending"))

(context "A context with value tags" (meta ((bug . "#402")))
  (it "is pending"))

==== Examples

==== Expectations

==== Matchers

==== Builtin Matchers

==== Hooks