Created
September 14, 2017 15:05
-
-
Save cgrand/6ca4c4e5a3396708e7462fcb88105ff9 to your computer and use it in GitHub Desktop.
Documenting specs inline
This file contains 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
(defmacro doc | |
"Returns a spec which acts in all points like the provided spec, | |
expect for describe/form where the docstring appears." | |
[docstring spec] | |
`(doc-impl ~docstring '~spec (delay (spec/spec ~spec)))) | |
(defn doc-impl [docstring form delayed-spec] | |
(reify spec/Spec | |
(conform* [_ x] (spec/conform* @delayed-spec x)) | |
(unform* [_ y] (spec/unform* @delayed-spec y)) | |
(explain* [_ path via in x] (spec/explain* @delayed-spec path via in x)) | |
(gen* [_ overrides path rmap] (spec/gen* @delayed-spec overrides path rmap)) | |
(with-gen* [_ gfn] (spec/with-gen* @delayed-spec gfn)) | |
(describe* [_] | |
`(doc ~docstring ~(if (keyword? form) form (spec/describe* @delayed-spec)))))) |
Christophe, can you give an example of usage with result ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expect or except ?