I am trying to use a macro in a step definition, and instead of having access to the value passed in to my step definition I get a symbol.
This is perhaps nothing more than me being relatively new to Clojure but it's certainly unexpected.
Given the the following scenario:
Scenario: Using macros inside step defintions
Given my words are replaced:
"""
My word is %{word}
"""
When I run my cukes with a step defintion like:
;; Step definition
(defmacro fmt [^String string]
(let [-re #"%\{(.*?)\}"
fstr (clojure.string/replace string -re "%s")
fargs (map #(read-string (second %)) (re-seq -re string))]
`(format ~fstr ~@fargs)))
(Given #"my words are replaced:" [string]
(let [word "interpolated"]
(assert (= (fmt string) "My word is interpolated")))
Then I get an error of:
Caused by: java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.CharSequence
at clojure.core$re_matcher.invoke(core.clj:4386)
at clojure.core$re_seq.invoke(core.clj:4411)
at cucumber.runtime.clj$fmt.invoke(api_steps.clj:18)
at clojure.lang.Var.invoke(Var.java:423)
at clojure.lang.AFn.applyToHelper(AFn.java:167)
at clojure.lang.Var.applyTo(Var.java:532)
at clojure.lang.Compiler.macroexpand1(Compiler.java:6468)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6546)
I've gisted the full backtrace if that's of use, and I'm running cukes via lein-cucumber.
From: https://github.com/cucumber/cucumber-jvm/issues/631