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

Added missing getLocation method in HookDefiniton and reenabled Clojure ... #471

Merged
merged 1 commit into from
Mar 5, 2013
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
20 changes: 15 additions & 5 deletions clojure/src/main/clj/cucumber/runtime/clj.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
(defn- -setUnreportedStepExecutor [cljb executor]
"executor")

(defn- location-str [{:keys [file line]}]
(str file ":" line))

(defn add-step-definition [pattern fun location]
(.addStepDefinition
@glue
Expand All @@ -72,7 +75,7 @@
(.argumentsFrom (JdkPatternArgumentMatcher. pattern)
(.getName step)))
(getLocation [_ detail]
(str (:file location) ":" (:line location)))
(location-str location))
(getParameterCount [_]
nil)
(getParameterType [_ n argumentType]
Expand All @@ -89,19 +92,21 @@

(defmulti add-hook-definition (fn [t & _] t))

(defmethod add-hook-definition :before [_ tag-expression hook-fun]
(defmethod add-hook-definition :before [_ tag-expression hook-fun location]
(let [te (TagExpression. tag-expression)]
(.addBeforeHook
@glue
(reify
HookDefinition
(getLocation [_ detail?]
(location-str location))
(execute [hd scenario-result]
(hook-fun))
(matches [hd tags]
(.eval te tags))
(getOrder [hd] 0)))))

(defmethod add-hook-definition :after [_ tag-expression hook-fun]
(defmethod add-hook-definition :after [_ tag-expression hook-fun location]
(let [te (TagExpression. tag-expression)
max-parameter-count (->> hook-fun class .getDeclaredMethods
(filter #(= "invoke" (.getName %)))
Expand All @@ -111,6 +116,8 @@
@glue
(reify
HookDefinition
(getLocation [_ detail?]
(location-str location))
(execute [hd scenario-result]
(if (zero? max-parameter-count)
(hook-fun)
Expand All @@ -130,12 +137,15 @@
(step-macros
Given When Then And But)

(defn- hook-location [file form]
{:file file
:line (:line (meta form))})

(defmacro Before [binding-form & body]
`(add-hook-definition :before [] (fn ~binding-form ~@body)))
`(add-hook-definition :before [] (fn ~binding-form ~@body) ~(hook-location *file* &form)))

(defmacro After [binding-form & body]
`(add-hook-definition :after [] (fn ~binding-form ~@body)))
`(add-hook-definition :after [] (fn ~binding-form ~@body) ~(hook-location *file* &form)))

(defn ^:private update-keys [f m]
(reduce-kv #(assoc %1 (f %2) %3) {} m))
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
<modules>
<module>core</module>
<module>picocontainer</module>
<!--<module>clojure</module>-->
<module>clojure</module>
<module>junit</module>
<module>jruby</module>
<module>jython</module>
Expand Down