On Jul 14, 6:58 pm, Stuart Sierra <
the.stuart.sie...@gmail.com> wrote:
> Namespace-wide fixtures ("once-fixtures") are easy -- they should just
> run around the top-level test function. That's something I can fix,
> and it will be sufficient for your example.
>
> But per-test fixtures ("each-fixtures") present a problem. If the
> fixtures are run around every test function, then they will be called
> multiple times when test functions are nested. Should they be called
> just around the top-level test functions, or just around the bottom-
> level test functions? And how do you determine where the "bottom" of
> the test function hierarchy is?
I don't think ns-test-hook should really care about this. Perhaps it
would be best to consider test-ns-hook a low-level construct that can
do whatever it wants with the defined tests and fixtures, and provide
some other means for specifying which tests will be run.
Alternatively (or additionally), provide a facility for tagging tests
and defining fixtures that are run around tests with a specific tag.
Then, you could simply use a tag that has no fixtures defined:
; no explicit tag implies "each"?
(deftest test1 ...)
(deftest test2 ...)
(deftest testgroup {:fixtures 'no-fixtures}
(test1)
(test2))
To get the fixtures called, though, deftest probably needs to return
something like:
(def testname
(fn [] (execute-test test-info-map ; we should have the map at
this point so we can form a closure, right?
(fn [] (actual-test-content-here)))
where execute-test would by default be bound to a function that runs
whatever fixtures the test has. A custom test-ns-hook could rebind
execute-test at will.
This could all be done with fixture macros manually too of course, but
wrapping functions are probably somewhat easier to write.
--
Jarkko
PS. For whatever reason, this stuff makes me think of monads. :)