-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature inquiry: a convenience function for validating a value against a spec #214
Comments
@aviflax Thanks for the idea, I appreciate it! At least for now, I'm going to keep Expound focused on just improving the spec error messages. This is method is useful, but I think it's a better fit for a separate library. |
Sure, that makes sense. Thanks for considering it and the gracious feedback!
|
For reference, in case someone finds it useful, here is a (require [clojure.test :refer :all])
(require [expound.alpha :as expound])
(require [clojure.spec.alpha :as s])
(defmethod assert-expr 'valid?
[message [_ spec actual]]
`(do-report
{:type (if (s/valid? ~spec ~actual) :pass :fail)
:message ~message
:expected "Success!\n"
:actual (expound/expound-str ~spec ~actual)}))
(declare handler)
(deftest example-test
(testing "that response is valid"
(let [{:keys [body]} (handler {:body-params {:sample "input"}})]
(is (valid? :my/spec body))))) At least in Cursive / IntelliJ this displays well. |
@devurandom Nice! |
I feel like I’ve written variations on this fn across a bunch of projects:
so I’m wondering whether this, or something similar, might be a good idea to include in Expound?
I’d be happy to submit a PR, if so.
Thank you!
The text was updated successfully, but these errors were encountered: