Created
January 7, 2019 01:59
-
-
Save arrdem/94dd85f5c18bbed22822b36efffa61dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns spec.extras.valid | |
(:require [clojure.spec.alpha :as s])) | |
(defn valid! | |
"`#'s/valid?` but throws an `ex-info` with `#'s/explain-data` of the | |
failure when `val` doesn't conform to `spec`. | |
Intended for always-on postconditions because `#'s/assert` is off by | |
default." | |
[spec val] | |
(if (s/valid? spec val) | |
true | |
(throw (ex-info (format "Failed to validate value %s as spec %s" | |
(pr-str val) spec) | |
(s/explain-data spec val))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment