Mercurial > lasercutter
diff src/clojure/contrib/mock/test_adapter.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/contrib/mock/test_adapter.clj Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,38 @@ 1.4 +;;; test_adapter.clj: clojure.test adapter for mocking/expectation framework for Clojure 1.5 + 1.6 +;; by Matt Clark 1.7 + 1.8 +;; Copyright (c) Matt Clark, 2009. All rights reserved. The use 1.9 +;; and distribution terms for this software are covered by the Eclipse 1.10 +;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php). 1.11 +;; By using this software in any fashion, you are 1.12 +;; agreeing to be bound by the terms of this license. You must not 1.13 +;; remove this notice, or any other, from this software. 1.14 + 1.15 +(ns clojure.contrib.mock.test-adapter 1.16 + (:require [clojure.contrib.mock :as mock]) 1.17 + (:use clojure.test 1.18 + clojure.contrib.ns-utils)) 1.19 + 1.20 +(immigrate 'clojure.contrib.mock) 1.21 + 1.22 +(defn report-problem 1.23 + "This function is designed to be used in a binding macro to override 1.24 +the report-problem function in clojure.contrib.mock. Instead of printing 1.25 +the error to the console, the error is logged via clojure.test." 1.26 + {:dynamic true} 1.27 + [fn-name expected actual msg] 1.28 + (report {:type :fail, 1.29 + :message (str msg " Function name: " fn-name), 1.30 + :expected expected, 1.31 + :actual actual})) 1.32 + 1.33 + 1.34 +(defmacro expect [& body] 1.35 + "Use this macro instead of the standard c.c.mock expect macro to have 1.36 +failures reported through clojure.test." 1.37 + `(binding [mock/report-problem report-problem] 1.38 + (mock/expect ~@body))) 1.39 + 1.40 + 1.41 +