Liking cljdoc? Tell your friends :D

stub-fn

A macro to stub arbitrary Clojure functions.

Usage

Leiningen dependency

stub-fn is available on Clojars. To use it in your project add the following to your project.clj dependency vector:

[fhofherr/stub-fn "0.1.0-SNAPSHOT"]

Without clojure.test

If you do not use clojure.test require the fhofherr.stub-fn.core namespace. To stub a function use the stub-fn macro. To verify invocations use either verify-invocations or invoked?.

With clojure.test

Users of clojure.test should use the fhofherr.stub-fn.clojure.test namespace instead. It re-exports the stub-fn macro and extends clojure.test to enable verification of invocations using the test-is macro. Instead of using fhofherr.stub-fn.core/verify-invocations users can do the following:

(ns some-test-ns
  (:require [clojure.test :refer :all]
            [fhofherr.stub-fn.clojure.test :refer [stub-fn]]))

(deftest using-test-is
  (let [f (stub-fn f [x])]
      (f 1)
      (is (invoked? f :times 1 :args {'x 1}))))

License

Copyright © 2017 Ferdinand Hofherr

Distributed under the MIT License.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close