1

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.

Adam Schmideg
  • 10,590
  • 10
  • 53
  • 83

2 Answers2

1

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

(fact {:midje/description (str n "not odd")} n => odd?)
Adam Schmideg
  • 10,590
  • 10
  • 53
  • 83
0

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.

ordnungswidrig
  • 3,140
  • 1
  • 18
  • 29