Domanda

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.

È stato utile?

Soluzione

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

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

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top