The new Clojure spec library provides support for data and function specification. In this first in a series of screencasts, Stuart Halloway discusses how spec provides leverage to achieve many returns for a small investment in describing your functions with spec.
spec provides leverage in the following areas:
- Error messages
- Example Data Generation
- Generative Testing
Clojure spec defines specifications for both data and functions. In addition to validity checking, specs can generate random samples of the data they specify. This capability enables an alternative to unit testing known as generative, or property-based, testing.
The "check" function automatically generates a large number of example inputs to a function and checks that the invocation of the function satisfies its specification. A complementary function "instrument" verifies that calls to a function satisfy the function's specification. In this screencast, Stuart Halloway demonstrates how to use both "check" and "instrument" to automatically leverage specs to better test your code.
spec: Customizing Generators
One benefit of Clojure specs is that they automatically provide data generators that produce values conforming to the spec which can be used for testing. In addition, you can compose your own generator to more precisely match your data model.
In this screencast, Stuart Halloway demonstrates techniques for creating and combining models of your input using the `bind` and `fmap` functions to produce custom generators.
Drive Actionable Insights When They Matter Most
This system was created for a very large e-commerce company, who would hold flash sales, but didn't understand how well these sales captured target users, where they were losing customers, and where errors on the site lost them a potential sale.
So Cognitect built a system that rapidly integrated data from multiple sources, and multiple shapes, into Datomic, our fully transactional, cloud-ready, distributed database, that never forgets. Then we reflected this stream of "user novelty" back out to a dashboard in near-real time. Our goal was to have a system that could drive actionable insights when they mattered most -- an application that had a real impact to the organization's bottom line.