Wrapping Up

In this chapter we’ve looked at how to specify the structure of both our data and our functions. You learned how to validate your data using a spec with s/valid?, as well as how to discover how it conformed with s/conform or how it failed with s/explain.

Additionally, you learned how to check for invalid calls with stest/instrument when working at the REPL or in tests, and how to automatically test a properly spec’d function using stest/check.

The spec library requires a fair amount of extra effort in the code you write, particularly if you take the extra step to ensure that the :args spec of any function generates high-quality inputs for testing. However, you also gain lots of leverage by doing so, and it’s entirely up to you how ...

Get Programming Clojure, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.