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

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

Merged
merged 1 commit into from
Mar 20, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions clojure/src/main/clj/cucumber/runtime/clj.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

36 changes: 15 additions & 21 deletions clojure/src/test/resources/cucumber/runtime/clojure/stepdefs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))