missbehave brief overview pasted by certainty on Wed May 18 21:44:35 2011

(use 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"
         (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))))))




;; Example output of ./csi -s behave.scm test.scm
;;
;; Missbehave features
;; Procedure stubs
;;   It can stub return values
;;  It provides temporary stubs
;; Procedure expectations
;; Arguments
;;   It checks arguments
;;   It mixes arguments and application count
;; Application-count
;;   It checks application count
;;   It checks application count > 1
;;   It checks for no calls
;; Pending
;;   [P] It is implicitly pending
;;   [P] It is explicitly pending
;; Simple be matchers
;;   It must be true
;;   It must be a string
;;   It can use standard operators
;;   It can use predicates
;; implicit subject
;;   It should (be 42)
;;   It should (be a number)
;;
;; 
;; Total: 13 Successful: 13 Pending: 0 Failures: 0

the output was actually added by certainty on Wed May 18 21:49:45 2011

;; Missbehave features
;; Procedure stubs
;;   It can stub return values
;;   It provides temporary stubs
;; Procedure expectations
;; Arguments
;;   It checks arguments
;;   It mixes arguments and application count
;; Application-count
;;   It checks application count
;;   It checks application count > 1
;;   It checks for no calls
;; Pending
;;   [P] It is implicitly pending
;;   [P] It is explicitly pending
;; Simple be matchers
;;   It must be true
;;   It must be a string
;;   It can use standard operators
;;   It can use predicates
;; implicit subject
;;   It should (be 42)
;;   It should (be a number)
;; 
;; 
;; Total: 15 Successful: 13 Pending: 2 Failures: 0