[ANN] Shrubbery 0.4.0, a stubbing, spying, and mocking library for Clojure protocols

123 views
Skip to first unread message

Brian Guthrie

unread,
Aug 22, 2016, 11:02:55 AM8/22/16
to clojure
Clojure protocols are a great way to encapsulate operations with side effects, but suffer from a lack of general test tooling. Shrubbery provides a small set of basic building blocks for working with them.

New in this release:

– A throws function, which returns an object suitable for use with the stub function that throws the named exception when invoked, as so:

(defprotocol SomeProtocol
  (explode [t]))

(let [astub (shrubbery/stub SomeProtocol 
              {:explode (shrubbery/throws RuntimeException "bang")})]
  (explode astub)) ;; throws RuntimeException "bang"

What Shrubbery provides:

 * stub, which accepts a variable list of protocols and a optional hashmap of simple value implementations and returns an object that reifies all given protocols;
 * spy, which accepts an object with at least one protocol implementation and returns a new implementation that tracks the number of times each of its members were called;
 * mock, which wraps a stub in a spy, allowing callers to supply basic function implementations and assert against those calls; and
 * calls/received?, which in conjunction with the Matcher protocol provide a way to query spies and assert against their state.

Shrubbery is test-framework-agnostic, avoids altering runtime state to the degree possible, and uses no macros. It supports Clojure versions 1.5-1.8; I haven't yet tested with 1.9. It should work nicely with automated refactoring operations like rename-function.


[com.gearswithingears/shrubbery "0.4.0"]

Cheers,

Brian
Reply all
Reply to author
Forward
0 new messages