I've started using clojure.test's use-fixtures feature. It's a great way
to clean up tests that have side-effects. But I noticed that it uses
alter-meta! in a way that simply adds the fixture function to the
existing list of fixtures:

    (defmethod use-fixtures :each [fixture-type & args]
      (add-ns-meta ::each-fixtures args))

    (defn- add-ns-meta
      "Adds elements in coll to the current namespace metadata as the
      value of key."
      [key coll]
      (alter-meta! *ns* assoc key (concat (key (meta *ns*)) coll)))

This is fine for non-interactive development, but when working in SLIME
or another interactive environment, you tend to re-eval your tests over
and over again. What this means is that your fixtures just get nested
deeper and deeper inside each other:

  (use-fixtures :each my-cleanup)

  (deftest my-messy-test [...])

Load that a few times and you end up running the equivalent of
(my-cleanup (my-cleanup (my-cleanup my-messy-test))).

My first instinct was just to fix it by assoc'ing coll into the ns meta
rather than concat'ing the existing fixture list first. But this would
mean that composed fixtures would be up to the user. However, it seems
like this is a major edge case; off the top of my head I can't think of
a time when you would actually want this behaviour.

Perhaps composing the fixture functions should be up to the user and
use-fixtures should replace the existing list? If not, then clojure.test
should offer an alternative to the existing behaviour that performs
replacement, perhaps as another multimethod.

-Phil

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to