summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hagelberg <technomancy@gmail.com>2009-10-07 10:54:52 -0700
committerChouser <chouser@n01se.net>2009-10-28 22:33:46 -0400
commitf5f2943dfd0128744227c3f42a630ea10dd40b24 (patch)
tree02aa06ac10224c9ce16b94c87bf5264313106163
parent6aab0f20e6bcc897b86a77b728af6fa0df93a2d8 (diff)
Don't repeatedly compose on calls to use-fixtures. Fixes #194.
Updated tests and added a docstring to use-fixtures. Signed-off-by: Chouser <chouser@n01se.net>
-rw-r--r--src/clj/clojure/test.clj8
-rw-r--r--test/clojure/test_clojure/test_fixtures.clj11
2 files changed, 16 insertions, 3 deletions
diff --git a/src/clj/clojure/test.clj b/src/clj/clojure/test.clj
index 0d7c4600..9be6dc0d 100644
--- a/src/clj/clojure/test.clj
+++ b/src/clj/clojure/test.clj
@@ -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))
diff --git a/test/clojure/test_clojure/test_fixtures.clj b/test/clojure/test_clojure/test_fixtures.clj
index 9a85b58b..0a6ff51a 100644
--- a/test/clojure/test_clojure/test_fixtures.clj
+++ b/test/clojure/test_clojure/test_fixtures.clj
@@ -16,6 +16,8 @@
(declare *a* *b* *c* *d*)
+(def *n* 0)
+
(defn fixture-a [f]
(binding [*a* 3] (f)))
@@ -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*))
@@ -39,3 +45,6 @@
(deftest can-use-each-fixtures
(is (= 7 *c*))
(is (= 11 *d*)))
+
+(deftest use-fixtures-replaces
+ (is (= *n* 1))) \ No newline at end of file