Permalink
Browse files

Two new functions have been added to work with a context or rather tr…

…ansport return values from one to another test in a given when then block.
  • Loading branch information...
maxweber committed Sep 8, 2011
1 parent 7cff74a commit 2a359512a766bb299a0587bc27d957acede31841
Showing with 20 additions and 2 deletions.
  1. +20 −2 src/lazyspec/core.clj
View
@@ -11,9 +11,9 @@
(map test-case (f fns))
{:doc (str name ": " doc)}))))))
-(def Scenario (clasp "Scenario" #(apply concat %)))
+(def Scenario (clasp "Scenario" flatten))
-(def Feature (clasp "Feature" identity))
+(def Feature (clasp "Feature" flatten))
(defn- block [name]
(fn [& fns]
@@ -29,3 +29,21 @@
(def When (block "When"))
(def Then (block "Then"))
+
+(defn capture [context fun f]
+ (with-meta (fn []
+ (let [r (f)
+ bindings (fun r)]
+ (apply swap! context assoc (apply concat bindings))
+ r))
+ (meta f)))
+
+(defn with-context [context f & args]
+ (with-doc (fn []
+ (apply f (map #(do
+ (if (keyword? %)
+ (if-let [val (% @context)]
+ val
+ %)
+ %)) args)))
+ (resolve-fn-doc f)))

0 comments on commit 2a35951

Please sign in to comment.