Skip to content

Commit

Permalink
make syntax nicer (rewritten for new backend changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
rplevy-draker committed Mar 19, 2012
1 parent bfeea61 commit f48aa96
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
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)))

0 comments on commit f48aa96

Please sign in to comment.