The issue is where do I specify that: (undo-fn ...patch...) => (fn [] (reset! visible-evidence-of-a-side- effect :happened!))
undo-fn is a multimethod in my design, which requires a corresponding defmethod for each patch type. I need to create one for the scope of the test, but defmethod by definition alters the top-level state of the system, and doesn't automatically unroll like let or binding does. On Dec 22, 6:33 am, Brian Marick <mar...@exampler.com> wrote: > I think I misunderstand the issue, because this works for me: > > (ns midje.util.git > (:use [midje.sweet])) > > ;; Code except for undo-patch is the same as before. > ;; ... > > ;; I pulled remove-patch out of undo-patch because I was > ;; getting a screwy read error I didn't want to figure out > ;; at 5 in the morning, but I'd probably do that anyway: > ;;http://codebetter.com/jeremymiller/2006/12/03/composed-method-pattern/ > > (defn remove-patch [patch] > (alter patches- #(remove (fn [p] (= patch p)) %))) > > (defn undo-patch [patch] > (let [fn (undo-fn patch)] > (dosync > (fn) > (remove-patch patch)))) > > (fact "The patch's undo-fn is called for its side effect and the patch is > forgotten" > (let [visible-evidence-of-a-side-effect (atom nil)] > (undo-patch ...patch...) => anything > (provided > (undo-fn ...patch...) => (fn [] (reset! > visible-evidence-of-a-side-effect :happened!)) > (remove-patch ...patch...) => :nothing-of-interest) > @visible-evidence-of-a-side-effect => :happened!)) > > 1855 $ lein midje midje.util.git > All claimed facts (2) have been confirmed. > 1856 $ > > ----- > Brian Marick, Artisanal Labrador > Contract programming in Ruby and Clojure > Author of /Ring/ (forthcoming; > sample:http://bit.ly/hfdf9T)www.exampler.com,www.exampler.com/blog,www.twitter.com/marick -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en