view 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 source
1 ;;; test_adapter.clj: clojure.test adapter for mocking/expectation framework for Clojure
3 ;; by Matt Clark
5 ;; Copyright (c) Matt Clark, 2009. All rights reserved. The use
6 ;; and distribution terms for this software are covered by the Eclipse
7 ;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php).
8 ;; By using this software in any fashion, you are
9 ;; agreeing to be bound by the terms of this license. You must not
10 ;; remove this notice, or any other, from this software.
12 (ns clojure.contrib.mock.test-adapter
13 (:require [clojure.contrib.mock :as mock])
14 (:use clojure.test
15 clojure.contrib.ns-utils))
17 (immigrate 'clojure.contrib.mock)
19 (defn report-problem
20 "This function is designed to be used in a binding macro to override
21 the report-problem function in clojure.contrib.mock. Instead of printing
22 the error to the console, the error is logged via clojure.test."
23 {:dynamic true}
24 [fn-name expected actual msg]
25 (report {:type :fail,
26 :message (str msg " Function name: " fn-name),
27 :expected expected,
28 :actual actual}))
31 (defmacro expect [& body]
32 "Use this macro instead of the standard c.c.mock expect macro to have
33 failures reported through clojure.test."
34 `(binding [mock/report-problem report-problem]
35 (mock/expect ~@body)))