其中一種可能性是writing your own emitter但這對您的特定目標可能是矯枉過正的。
或者,你可以猴子打補丁負責的功能格式化的預期值:
(require '[midje.util.exceptions :as e]
'[midje.emission.plugins.util :as u])
(defn- format-captured-throwable
[ex]
(if (e/captured-throwable? ex)
;; ... adjust this to your needs ...
(pr-str 'this-is-your-exception (e/throwable ex))))
(alter-var-root
#'u/attractively-stringified-value
(fn [f]
#(or (format-captured-throwable %) (f %))))
format-captured-throwable
必須產生一個字符串,雖然,這意味着直接打印堆棧跟蹤會讓它最終遠不midje的測試報告。
user=> (fact (throw (Exception. "khaaaaaaaan.")) => :not-khan)
FAIL at (form-init4689442922606051135.clj:1)
Expected: :not-khan
Actual: this-is-your-exception #<Exception java.lang.Exception: khaaaaaaaan.>
來源
2014-12-06 17:35:20
xsc