Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntactic sugar tweak for clojure dsl #244

Closed
rplevy-draker opened this issue Mar 5, 2012 · 7 comments
Closed

syntactic sugar tweak for clojure dsl #244

rplevy-draker opened this issue Mar 5, 2012 · 7 comments

Comments

@rplevy-draker
Copy link
Contributor

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.

For example:

(defmacro Given'
  [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.

If you agree with this feature, I'll submit a pull request for a modified clojure/src/main/resources/cucumber/runtime/clojure/dsl.clj

@rplevy-draker
Copy link
Contributor Author

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
             (fn [m#]
               `((def ~m# #'~existing-macro)
                 (. #'~m# (setMacro))))
             new-macros)))

(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

@aslakhellesoy
Copy link
Contributor

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.

@nilswloka
Copy link
Member

Just noticed that this will probably be obsolete if the clojure-native pull request is merged (#265).

@aslakhellesoy
Copy link
Contributor

Yes, obsolete now

@rplevy-draker
Copy link
Contributor Author

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.

@aslakhellesoy
Copy link
Contributor

See comment in #248

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants