amitrathore / conjure

a mocking library for clojure
http://s-expressions.com
73 stars 9 forks source link

Pass args to function we use as the stub #1

Closed AlexBaranosky closed 12 years ago

AlexBaranosky commented 12 years ago

Code change:

(defn stub-fn [function-name return-value]
  (swap! call-times assoc function-name [])
  (fn [& args]
    (swap! call-times update-in [function-name] conj args)
    (if (fn? return-value)
      (apply return-value args) ;; pass the args in
      return-value)))

This way you can say:

(binding [logger (fn [msg] (println "we're logging your message: " msg))]
  (is (= :foo (bar-maker))))