clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
practicalli-john 2020-06-08T01:53:48.210100Z

After quite bit of experimentation, I refactored my specs, code and tests for a bank account and learnt a bit about qualified keys and auto-resolve macro. I have specs that I can use with my clojure.test unit tests I updated the journal to show how I would create the specs, unit tests and code now https://github.com/practicalli/leveraging-spec/blob/master/src/practicalli/bank_account_design_journal.clj And the specs are in their own namespace, using a Clojure Common extension, .cljc (I believe all the specs are host neutral) https://github.com/practicalli/leveraging-spec/blob/master/test/practicalli/bank_account_spec.cljc

practicalli-john 2020-06-08T07:10:56.211600Z

Oh yes, labels. At 2.30am I tend to forget things :white_frowning_face: I find fdef a bit opaque, some more reading and experimenting to do. Thanks for spotting the bug in last-name, not intentional. Thanks for the review

practicalli-john 2020-06-08T13:53:04.212600Z

I got the spec/or expression to wrap the :req and :req-un versions working. I have my fdef :args validating after instrumenting. Still working on testing the :ret in the fdef...

seancorfield 2020-06-08T16:46:16.213700Z

Right, :args is for instrument -- checking that your code is calling the function correctly -- and :ret/`:fn` are for generative testing, to make sure your function behaves correctly.

seancorfield 2020-06-08T16:47:35.213900Z

With instrument, :ret and :fn are ignored. With check, :args is used to generate conforming arguments and then the function is called and the :ret and :fn specs are checked against the return value and against the arguments/return value respectively.

seancorfield 2020-06-08T16:48:42.214100Z

A lot of people don't feel the docs are clear enough about :args/`instrument` and :ret/`:fn`/`check`

practicalli-john 2020-06-08T17:50:41.216300Z

I’m comfortable with instrument for now. I don’t seem to have something right with check yet, but will look again tomorrow. Thanks.

seancorfield 2020-06-08T03:01:50.210500Z

@jr0cket Is this a deliberate bug to fall out of testing later? https://github.com/practicalli/leveraging-spec/blob/master/src/practicalli/bank_account_design_journal.clj#L56

seancorfield 2020-06-08T03:10:48.210800Z

:args should be a sequence spec, using s/cat: https://github.com/practicalli/leveraging-spec/blob/master/src/practicalli/bank_account_design_journal.clj#L422

seancorfield 2020-06-08T03:11:59.211100Z

Do you understand why this doesn't work? https://github.com/practicalli/leveraging-spec/blob/master/src/practicalli/bank_account_design_journal.clj#L337-L344

seancorfield 2020-06-08T03:13:15.211400Z

s/or requires labels for the alternatives: (s/or :qualified (s/keys :req [...]) :unqualified (s/keys :req-un [...]))