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