view src/clojure/test_clojure/test_fixtures.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
line wrap: on
line source
1 ; Copyright (c) Rich Hickey. All rights reserved.
2 ; The use and distribution terms for this software are covered by the
3 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 ; which can be found in the file epl-v10.html at the root of this distribution.
5 ; By using this software in any fashion, you are agreeing to be bound by
6 ; the terms of this license.
7 ; You must not remove this notice, or any other, from this software.
8 ;
9 ;;; test_fixtures.clj: unit tests for fixtures in test.clj
11 ;; by Stuart Sierra
12 ;; March 28, 2009
14 (ns clojure.test-clojure.test-fixtures
15 (:use clojure.test))
17 (declare *a* *b* *c* *d*)
19 (def *n* 0)
21 (defn fixture-a [f]
22 (binding [*a* 3] (f)))
24 (defn fixture-b [f]
25 (binding [*b* 5] (f)))
27 (defn fixture-c [f]
28 (binding [*c* 7] (f)))
30 (defn fixture-d [f]
31 (binding [*d* 11] (f)))
33 (defn inc-n-fixture [f]
34 (binding [*n* (inc *n*)] (f)))
36 (use-fixtures :once fixture-a fixture-b)
38 (use-fixtures :each fixture-c fixture-d inc-n-fixture)
39 (use-fixtures :each fixture-c fixture-d inc-n-fixture)
41 (deftest can-use-once-fixtures
42 (is (= 3 *a*))
43 (is (= 5 *b*)))
45 (deftest can-use-each-fixtures
46 (is (= 7 *c*))
47 (is (= 11 *d*)))
49 (deftest use-fixtures-replaces
50 (is (= *n* 1)))