In my cucumber step definitions I find it convenient to wrap the Given/When/Then macros in what I consider to be slightly better syntactic sugar.
[re binding-form & body]
`(Given ~re (fn ~binding-form ~@body)))
It occurred to me that there's no reason to expose the (fn  ... ) in step definitions, for any use case I can imagine. So why not make this the default syntax?
Looking at the way the dsl is implemented I think the best way to do this is not to change the implementation of stepdef at all, but just replace for example (def Given stepdef) with a defmacro expressions similar the one shown above.
(def Given stepdef)
If you agree with this feature, I'll submit a pull request for a modified clojure/src/main/resources/cucumber/runtime/clojure/dsl.clj
After looking at the cucumber-jvm Clojure DSL code, this is how I now do it in my step definition code:
(defmacro stepdef-sugar [re binding-form & body]
`(stepdef ~re (fn ~binding-form ~@body)))
(defmacro ^:private clone-macro [existing-macro new-macros]
(cons 'do (mapcat
`((def ~m# #'~existing-macro)
(. #'~m# (setMacro))))
(clone-macro stepdef-sugar [Given When Then And But])
This would be pretty much the exact code I would add to https://github.com/cucumber/cucumber-jvm/blob/master/clojure/src/main/resources/cucumber/runtime/clojure/dsl.clj
I don't know enough Clojure to have an opinion on this, so if you say this is better I'm sure it is! Please send along the pullreq.
Just noticed that this will probably be obsolete if the clojure-native pull request is merged (#265).
Yes, obsolete now
So by obsolete do you mean it is incompatible? I agree, that is the case. However, I would still like to add this feature to cucumber-jvm. It will just need to be written differently.
See comment in #248
Attribution. Closes #244, #267