动态计算中间事实的描述

时间:2013-05-22 11:43:00

标签: testing clojure midje

我想写一个函数来分解一些常见的事实,比如这个

(defn check-odd-and-positive
  [n]
  (fact (str n " not odd") n => odd?)
  (fact (str n " not positive") n => positive?))

(facts "about the answer"
  (check-odd-and-positive 42))

但它不会导致“42不奇怪”作为事实的描述。我知道用表格事实可以达到类似的效果,但我希望能够在事实组之间分享这样的事实。

2 个答案:

答案 0 :(得分:1)

我发现,截至1.6中间metadata非常简单

(fact {:midje/description (str n "not odd")} n => odd?)

答案 1 :(得分:0)

你可以在这里使用宏

(defmacro check-odd-and-positive [n]
  `(fact ~(str n " not odd") n => odd?)
  `(fact ~(str n " not positive" n => positive?))

但是,midje包含报告中的测试值,因此我无法清楚地知道为什么这是必要的。