Skip to content

Commit

Permalink
Don't repeatedly compose on calls to use-fixtures. Fixes #194.
Browse files Browse the repository at this point in the history
Updated tests and added a docstring to use-fixtures.

Signed-off-by: Chouser <chouser@n01se.net>
  • Loading branch information
technomancy authored and Chouser committed Oct 29, 2009
1 parent 6aab0f2 commit f5f2943
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/clj/clojure/test.clj
Expand Up @@ -825,9 +825,13 @@ Chas Emerick, Allen Rohner, and Stuart Halloway",
"Adds elements in coll to the current namespace metadata as the
value of key."
[key coll]
(alter-meta! *ns* assoc key (concat (key (meta *ns*)) coll)))
(alter-meta! *ns* assoc key coll))

(defmulti use-fixtures (fn [fixture-type & args] fixture-type))
(defmulti use-fixtures
"Wrap test runs in a fixture function to perform setup and
teardown. Using a fixture-type of :each wraps every test
individually, while:once wraps the whole run in a single function."
(fn [fixture-type & args] fixture-type))

(defmethod use-fixtures :each [fixture-type & args]
(add-ns-meta ::each-fixtures args))
Expand Down
11 changes: 10 additions & 1 deletion test/clojure/test_clojure/test_fixtures.clj
Expand Up @@ -16,6 +16,8 @@

(declare *a* *b* *c* *d*)

(def *n* 0)

(defn fixture-a [f]
(binding [*a* 3] (f)))

Expand All @@ -28,9 +30,13 @@
(defn fixture-d [f]
(binding [*d* 11] (f)))

(defn inc-n-fixture [f]
(binding [*n* (inc *n*)] (f)))

(use-fixtures :once fixture-a fixture-b)

(use-fixtures :each fixture-c fixture-d)
(use-fixtures :each fixture-c fixture-d inc-n-fixture)
(use-fixtures :each fixture-c fixture-d inc-n-fixture)

(deftest can-use-once-fixtures
(is (= 3 *a*))
Expand All @@ -39,3 +45,6 @@
(deftest can-use-each-fixtures
(is (= 7 *c*))
(is (= 11 *d*)))

(deftest use-fixtures-replaces
(is (= *n* 1)))

0 comments on commit f5f2943

Please sign in to comment.