tacular is a library that supplements spec with additional useful functionality. It supports both Clojure and ClojureScript.
Current features include:
-
Integration with
clojure.test
/cljs.test
-
Using regular expressions as specs
Grab tacular from Clojars:
tacular adds an additional assertion for is
: checks?
.
This takes the same arguments as clojure.spec.test/check
.
In order to use this, you will need require the io.clojure.tacular.clojure-test
namespace.
(ns com.example.foo-test
(:require [clojure.test :as t :refer [deftest is]
[com.example.foo :as foo]
[io.clojure.tacular.clojure-test])
(deftest test-bar
(is (checks? `foo/bar)))
With tacular, you can now use regular expressions as specs! There are two ways to do this:
-
Using the
re-matches?
function. -
Using regular expressions directly
Moreover, if you have Gary Fredericks’ excellent test.chuck library availabe, you’ll even get a generator (but not in ClojureScript, sadly).
This way is straightforward, just use the io.clojure.tacular/re-matches?
function with a regular expression as an argument.
(ns com.example.foo
(:require [clojure.spec :as s]
[io.clojure.tacular :refer [re-matches?]))
(s/def ::foo (re-matches? #”fo+”))