diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/test_clojure/test_fixtures.clj	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,50 @@
     1.4 +;   Copyright (c) Rich Hickey. All rights reserved.
     1.5 +;   The use and distribution terms for this software are covered by the
     1.6 +;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
     1.7 +;   which can be found in the file epl-v10.html at the root of this distribution.
     1.8 +;   By using this software in any fashion, you are agreeing to be bound by
     1.9 +;   the terms of this license.
    1.10 +;   You must not remove this notice, or any other, from this software.
    1.11 +;
    1.12 +;;; test_fixtures.clj: unit tests for fixtures in test.clj
    1.13 +
    1.14 +;; by Stuart Sierra
    1.15 +;; March 28, 2009
    1.16 +
    1.17 +(ns clojure.test-clojure.test-fixtures
    1.18 +  (:use clojure.test))
    1.19 +
    1.20 +(declare *a* *b* *c* *d*)
    1.21 +
    1.22 +(def *n* 0)
    1.23 +
    1.24 +(defn fixture-a [f]
    1.25 +  (binding [*a* 3] (f)))
    1.26 +
    1.27 +(defn fixture-b [f]
    1.28 +  (binding [*b* 5] (f)))
    1.29 +
    1.30 +(defn fixture-c [f]
    1.31 +  (binding [*c* 7] (f)))
    1.32 +
    1.33 +(defn fixture-d [f]
    1.34 +  (binding [*d* 11] (f)))
    1.35 +
    1.36 +(defn inc-n-fixture [f]
    1.37 +  (binding [*n* (inc *n*)] (f)))
    1.38 +
    1.39 +(use-fixtures :once fixture-a fixture-b)
    1.40 +
    1.41 +(use-fixtures :each fixture-c fixture-d inc-n-fixture)
    1.42 +(use-fixtures :each fixture-c fixture-d inc-n-fixture)
    1.43 +
    1.44 +(deftest can-use-once-fixtures
    1.45 +  (is (= 3 *a*))
    1.46 +  (is (= 5 *b*)))
    1.47 +
    1.48 +(deftest can-use-each-fixtures
    1.49 +  (is (= 7 *c*))
    1.50 +  (is (= 11 *d*)))
    1.51 +
    1.52 +(deftest use-fixtures-replaces
    1.53 +  (is (= *n* 1)))
    1.54 \ No newline at end of file