marick / Midje

Midje provides a migration path from clojure.test to a more flexible, readable, abstract, and gracious style of testing
MIT License
1.68k stars 128 forks source link

Prerequisite with dynamic arguments #467

Open viebel opened 4 years ago

viebel commented 4 years ago

I'd like to be able to define prerequisite with a dynamic argument and access this argument in the mocking value. For instance, I'd like to be able to write something like this:

(defn bar [x])
(defn foo [x]
  (bar x))

(fact
 (foo 2) => 2
 (provided (bar anything) => anything))

The problem in this code is that the anything after the arrow doesn't have the value of the anything before the arrow.

Does my request make sense?

viebel commented 3 years ago

Could anyone help on this one?

philomates commented 3 years ago

metaconstants might do something similar.

like

(defn bar [x])
(defn foo [x]
  (bar x))

(fact
 (foo 2) => ..some-arg..
 (provided (bar ..some-arg..) => ..some-arg..))

Are you somehow trying to express strong constraints between what flows in and out of subcalls? I generally try to avoid such tests because it doesn't test results but rather implementation, so when you refactor your implementation you have to update all your tests.