1. Moritz Heidkamp
  2. missbehave

Commits

David Krentzlin  committed 803712a

added examples for self-contained specs

  • Participants
  • Parent commits 34ca88e
  • Branches default

Comments (0)

Files changed (4)

File behave.scm

View file
  • Ignore whitespace
       (report-summary-plain! data agenda)))
 
 (define (report-summary-with-colors! data agenda)
-  (newline)
-  (newline)
   (let ((failure-count (report-agenda-failed agenda)))
-    (if (= failure-count 1)
-        (fmt #t (fmt-red (fmt-bold "There has been 1 failure ")))
-        (fmt #t (fmt-red (cat (fmt-bold (cat "There have been " (report-agenda-failed agenda) " failures")))))))
-  (newline)
-  (newline)
-  (report-failures (report-agenda-failed-examples agenda))
+    (unless (zero? failure-count)
+      (newline)
+      (newline)
+      (if (= failure-count 1)
+          (fmt #t (fmt-red (fmt-bold "There has been 1 failure ")))
+          (fmt #t (fmt-red (cat (fmt-bold (cat "There have been " (report-agenda-failed agenda) " failures"))))))
+      (newline)
+      (newline)
+      (report-failures (report-agenda-failed-examples agenda))))
   (newline)
   (newline)
   (fmt #t (cat
   (zero? (report-agenda-failed agenda)))
 
 (define (report-summary-plain! data agenda)
-  (newline)
-  (newline)
   (let ((failure-count (report-agenda-failed agenda)))
-    (if (= failure-count 1)
-        (printf "There has been 1 failure~%")
-        (printf "There have been ~A failures ~%" (report-agenda-failed agenda))))
-  (newline)
-  (report-failures (report-agenda-failed-examples agenda))
+    (unless (zero? failure-count)
+      (newline)
+      (newline)
+      (if (= failure-count 1)
+          (printf "There has been 1 failure~%")
+          (printf "There have been ~A failures ~%" (report-agenda-failed agenda)))
+      (newline))
+    (report-failures (report-agenda-failed-examples agenda)))
   (newline)
   (newline)
   (printf "Total: ~A Successful: ~A Pending: ~A Failures: ~A"

File missbehave.scm

View file
  • Ignore whitespace
       (filter-examples context #f exclude))
      (else  (context-examples context))))))
 
-    
 (define (run-example-with-hooks example context reporter)
   (reporter example mode: 'adhoc)
   

File spec/self-running.scm

View file
  • Ignore whitespace
+(use missbehave)
+
+(run-specification
+  (call-with-specification
+   (make-empty-specification)
+   (lambda () 
+     (include "spec.scm"))))

File spec/spec.scm

View file
  • Ignore whitespace
+;; 
+;; %%HEADER%%
+;; 
+
+;(load "./missbehave.scm")
+;(import missbehave)
+(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"
+         (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))))))