tacular: What’s missing from spec
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


tacular: What’s mssing from spec

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:

Clojars Project

clojure.test/cljs.test integration

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]

(deftest test-bar
  (is (checks? `foo/bar)))

Regular expressions as specs

With tacular, you can now use regular expressions as specs! There are two ways to do this:

  1. Using the re-matches? function.

  2. 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).

Using re-matches?

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+”))

Using regular expressions directly

For a less verbose experience, you can just import the io.clojure.tacular.implicits namespace. Once you do that, all regular expressions become specs.

(ns com.example.foo
 (:require [clojure.spec :as s]

(s/def ::foo #”fo+”)