Fork me on GitHub
#clojure-spec
<
2020-06-08
>
practicalli-johnny01:06:48

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

seancorfield03:06:15

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

practicalli-johnny07:06:56

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-johnny13:06:04

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

seancorfield16:06:16

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.

seancorfield16:06:35

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.

seancorfield16:06:42

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

practicalli-johnny17:06:41

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