I want to write a function to factor out some common facts, like this

(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))

But it doesn't result in "42 not odd" as the description of the fact. I know a similar effect could be achieved with tabular facts, but I want to be able to share such a fact among fact groups.

有帮助吗?

解决方案

I found out, it's quite simple with metadata as of midje 1.6

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

其他提示

You can go with a macro here

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

However, midje includes the tested value in the report, so I cannot clearly see why this is necessary at all.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top