marick / Midje

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

Check arity of functions being mocked #433

Closed philomates closed 6 years ago

philomates commented 6 years ago

Addresses https://github.com/marick/Midje/issues/431 For a test like this:

(defn my-inc 
  ([a b] (- (+ a (inc b)) b))
  ([a b c] (- (+ a (inc b)) b))
  ([a b c d & others] 1))

(defn strange-adder [a b]
  (+ (my-inc a) b))

(fact
  (strange-adder 1 2) => 300
  (provided (my-inc 1) => 298))

You will get output like this

FAIL at (aaaaaa_the_basics.clj:292)
You faked #'my-inc with an argument count that doesn't match the function's defined arguements:
Provided 1 argument(s), where valid options are: 2, 3, or 4+ arguments

FAIL at (aaaaaa_the_basics.clj:292)
These calls were not made the right number of times:
    (my-inc 1) [expected at least once, actually never called]