Skip to content

Commit

Permalink
Added some matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
pbalduino committed Apr 14, 2012
1 parent 5d8f7b6 commit f378b27
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 10 deletions.
40 changes: 37 additions & 3 deletions src/north/core.clj
@@ -1,13 +1,47 @@
(ns north.core)
(set! *warn-on-reflection* true)

(def ^:dynamic test-map {})

(defmacro describe [description & body]
`(do
(in-ns 'north.core)
(def test-map (assoc test-map (keyword ~description) {}))
(println test-map)
(println (format "before %s" test-map))

(println (format "description %s" ~description))

(def test-map
(assoc test-map
(keyword ~description) {}))

(println (format "after %s" test-map))
~body))

(defmacro context [description & body]
`(do
()))
~body))

(defmacro it [description & body]
`(defn (symbol ~description) []
~body))

(defn should
([result matcher]
(matcher result))
([result matcher expectation]
(matcher result expectation)))

(defn- verify [result expectation operation description]
(assert (operation result expectation) (format "Assertion failed. %s was expected to be %s %s" result description expectation)))

(defn be-not-equals [result expectation]
(verify result expectation not= "different than"))

(defn be-equals [result expectation]
(assert (= result expectation) (format "Assertion failed. %s was expected to be %s" result expectation)))

(defn be-true [result]
(be-equals result true))

(defn be-false [result]
(be-equals result false))
41 changes: 34 additions & 7 deletions test/north/test/core.clj
@@ -1,10 +1,37 @@
(ns north.test.core
(:use [north.core]))

(describe "North"
(context "using context"
(it "should test simple assertions"
(should (= 1 1) be-true)
(should (= 1 0) be-false)
(should (+ 1 1) be-equals 2)
(should (+ 1 1) be-not-equals 1))))
(println
(macroexpand
'(describe "North"
(context "using context"
(it "should test simple assertions"
(should (= 1 1) be-true)
(should (= 1 0) be-false)
(should (+ 1 1) be-equals 2)
(should (+ 1 1) be-not-equals 1))))))

(do
(clojure.core/in-ns
(quote north.core))
(clojure.core/println
(clojure.core/format "before %s" north.core/test-map))
(clojure.core/println
(clojure.core/format "description %s" "North"))
(def north.core/test-map
(clojure.core/assoc north.core/test-map
(clojure.core/keyword "North") {}))
(clojure.core/println
(clojure.core/format "after %s" north.core/test-map))
((context "using context"
(it "should test simple assertions"
(should (= 1 1) be-true)
(should (= 1 0) be-false)
(should (+ 1 1) be-not-equals 1)
(should (+ 1 1) be-equals 2)

true
)
)
)
)

0 comments on commit f378b27

Please sign in to comment.