From f5f2943dfd0128744227c3f42a630ea10dd40b24 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Wed, 7 Oct 2009 10:54:52 -0700 Subject: [PATCH] Don't repeatedly compose on calls to use-fixtures. Fixes #194. Updated tests and added a docstring to use-fixtures. Signed-off-by: Chouser --- src/clj/clojure/test.clj | 8 ++++++-- test/clojure/test_clojure/test_fixtures.clj | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/clj/clojure/test.clj b/src/clj/clojure/test.clj index 0d7c4600d1..9be6dc0d3f 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 9a85b58b0d..0a6ff51a14 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