Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make Clojure DSL syntax cleaner (rewritten as modification of new back-end) #267

Merged
merged 1 commit into from

3 participants

@rplevy-draker

No description provided.

@rplevy-draker

This replaces #248, so I closed that one.

@nilswloka
Collaborator

You probably want to change the template function for the reified Snippet in clojure-snippet (https://github.com/cucumber/cucumber-jvm/blob/master/clojure/src/main/clj/cucumber/runtime/clj.clj#L22) to reflect the new syntax.

@rplevy-draker

Hmm, good catch. So this is where it suggests a definition for a missing feature...

@aslakhellesoy

I moved the old to ClojureSnippet class from main to test in https://github.com/cucumber/cucumber-jvm/blob/master/clojure/src/test/java/cucumber/runtime/clojure/ClojureSnippet.java

Now its only purpose is to test snippets, and we must manually make sure the snippet templates are in sync. That's fine.

I'll go ahead and change it.

@rplevy-draker

I actually wrote it earlier, but there was an internet outage, so I went out to enjoy the nice weather. I'll make it work with this change right now.

@aslakhellesoy

Just about to push now :-)

Let me know if that's not right...

@aslakhellesoy aslakhellesoy merged commit f48aa96 into cucumber:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
19 clojure/src/main/clj/cucumber/runtime/clj.clj
@@ -119,19 +119,18 @@
(defmacro step-macros [& names]
(cons 'do
(for [name names]
- `(defmacro ~name [pattern# fun#]
- `(add-step-definition ~pattern# ~fun#
+ `(defmacro ~name [pattern# binding-form# & body#]
+ `(add-step-definition ~pattern#
+ (fn ~binding-form# ~@body#)
'~{:file *file*
:line (:line (meta ~'&form))})))))
(step-macros
Given When Then And But)
-(defmacro Before [& fun]
- (when (not (empty? fun))
- (let [fun (first fun)]
- `(add-hook-definition :before [] ~fun))))
-(defmacro After [& fun]
- (when (not (empty? fun))
- (let [fun (first fun)]
- `(add-hook-definition :after [] ~fun))))
+(defmacro Before [binding-form & body]
+ `(add-hook-definition :before [] (fn ~binding-form ~@body)))
+
+(defmacro After [binding-form & body]
+ `(add-hook-definition :after [] (fn ~binding-form ~@body)))
+
View
36 clojure/src/test/resources/cucumber/runtime/clojure/stepdefs.clj
@@ -2,30 +2,24 @@
(def some-state (atom "'Before' hasn't run."))
-(Before
- (fn []
- (do
- (reset! some-state "'Before' has run.")
- (println "Executing 'Before'."))))
+(Before []
+ (reset! some-state "'Before' has run.")
+ (println "Executing 'Before'."))
-(After
- (fn []
- (println (str "Executing 'After' " @some-state))))
+(After []
+ (println (str "Executing 'After' " @some-state)))
-(Given #"^I have (\d+) cukes in my belly$"
- #(eat (Float. %1)))
+(Given #"^I have (\d+) cukes in my belly$" [cuke-count]
+ (eat (Float. cuke-count)))
-(Given #"^I have this many cukes in my belly:$"
- #(doseq [x (.raw %1)] (eat (Float. (first x)))))
+(Given #"^I have this many cukes in my belly:$" [cuke-table]
+ (doseq [x (.raw cuke-table)] (eat (Float. (first x)))))
-(When #"^there are (\d+) cukes in my belly$"
- (fn [expected]
- (assert (= (last-meal) (Float. expected)))))
+(When #"^there are (\d+) cukes in my belly$" [expected]
+ (assert (= (last-meal) (Float. expected))))
-(Then #"^the (.*) contains (.*)$"
- (fn [container, ingredient]
- (assert (= "glass" container))))
+(Then #"^the (.*) contains (.*)$" [container ingredient]
+ (assert (= "glass" container)))
-(When #"^I add (.*)$"
- (fn [liquid]
- (assert (= "milk" liquid))))
+(When #"^I add (.*)$" [liquid]
+ (assert (= "milk" liquid)))
Something went wrong with that request. Please try again.