slagyr / speclj

pronounced "speckle": a TDD/BDD framework for Clojure.
MIT License
459 stars 58 forks source link

Custom shoulds #54

Closed RyanMcG closed 11 years ago

RyanMcG commented 11 years ago

RSpec has custom matchers, should speclj ease the creation of custom shoulds?

While working with clojure.core.matrix I encountered a custom == function in the operators namespace. Although I could do something like

(require '[clojure.core.matrix.operators :as mo])
(should-be (partial mo/== expected-form) actual-form)

The resulting output on failure is less descriptive than I'd hope.

I chose to simply make a new namespace, speclj.shoulds.matrix.core with the desired should-matrix== macro (I'm not psyched about the name I came up with but I couldn't think of anything better). This was not particularly hard since I basically copied the source code for should=. Nonetheless, I was unable to find a standard way to make custom shoulds or a well known place to put them. The following seem like decent ideas to me:

The last point is probably the most ambitious and I expect some would find it the least valuable. I didn't get anywhere (my macro-fu is less than guru-like) but my idea was something with a simple usage like:

(defshould= should-matrix== equals-function "some string following 'using: '")

Which would expand to the defmacro I wrote to define should-matrix==.

I'm very open to other ideas, criticisms or other thoughts about this issue. Does anyone else see any value in custom shoulds?

slagyr commented 11 years ago

Ryan,

Thanks for the suggestions.

Documentation for writing custom 'shoulds' is a an easy one. We should do that.

Guidelines for where to put them… yeah this could be helpful. Maybe an example scenario.

Macros to make custom shoulds easier to create: Hmm…. we have to try and refactor the existing shoulds into your format. See if there is a simple common structure that could be used.

Please feel free to make contributions.

Micah

On Jul 13, 2013, at 10:55 PM, Ryan McGowan notifications@github.com wrote:

RSpec has custom matchers, should speclj ease the creation of custom shoulds?

While working with clojure.core.matrix I encountered a custom == function in the operators namespace. Although I could do something like

(require '[clojure.core.matrix.operators :as mo]) (should-be (partial mo/== expected-form) actual-form) The resulting output on failure is less descriptive than I'd hope.

I chose to simply make a new namespace, speclj.shoulds.matrix.core with the desired should-matrix== macro (I'm not psyched about the name I came up with but I couldn't think of anything better). This was not particularly hard since I basically copied the source code for should=. Nonetheless, I was unable to find a standard way to make custom shoulds or a well known place to put them. Following seem like decent ideas to me:

Guidelines for where to put custom shoulds so others can find and use them Documentation on how to write custom shoulds Macros or functions to make the definition of custom shoulds easier. The last point is probably the most ambitious and I expect some would find it the least valuable. I didn't get anywhere (my macro-fu is less than guru-like) but my idea was something with a simple usage like:

(defshould= should-matrix== equals-function "some string following 'using: '") Which would expand to the defmacro I wrote to define should-matrix==.

I'm very open to other ideas, criticisms or other thoughts about this issue. Does anyone else see any value in custom shoulds?

— Reply to this email directly or view it on GitHub.

RyanMcG commented 11 years ago

Documentation for writing custom 'shoulds' is a an easy one. We should do that.

Great!

Guidelines for where to put them… yeah this could be helpful. Maybe an example scenario.

Well, I was looking for a custom should that used the matrix == operator. I had no idea where to look if someone had already done it. If everyone put custom shoulds somewhere under a consistent namespace (my thought being speclj.shoulds) then my query would have been more easily resolved.

Macros to make custom shoulds easier to create: Hmm…. we have to try and refactor the existing shoulds into your format. See if there is a simple common structure that could be used.

That crossed my mind! But since I failed at creating a defshould= macro I decided I probably wouldn't be the one to do it. :smile:

Please feel free to make contributions.

Definitely! Should I try to stub something out on the wiki?

slagyr commented 11 years ago

I'm going to close this issue due to lack of activity. If there is interest we can open it back up.