David Krentzlin avatar David Krentzlin committed 803712a

added examples for self-contained specs

Comments (0)

Files changed (4)

       (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"
       (filter-examples context #f exclude))
      (else  (context-examples context))))))
 
-    
 (define (run-example-with-hooks example context reporter)
   (reporter example mode: 'adhoc)
   

spec/self-running.scm

+(use missbehave)
+
+(run-specification
+  (call-with-specification
+   (make-empty-specification)
+   (lambda () 
+     (include "spec.scm"))))
+;; 
+;; %%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))))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.