1

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

(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 不奇怪”作为事实的描述。我知道使用表格事实可以实现类似的效果,但我希望能够在事实组之间分享这样的事实。

4

2 回答 2

1

我发现,从midje 1.6 开始,元数据非常简单

(fact {:midje/description (str n "not odd")} n => odd?)
于 2013-12-29T09:24:05.257 回答
0

你可以在这里使用宏

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

但是,midje 在报告中包含了测试值,所以我无法清楚地看到为什么这是必要的。

于 2013-05-22T13:37:28.923 回答