Closed obmarg closed 8 years ago
An idea of how this could look:
defmodule Example do
use ExUnitFixtures.FixtureModule
@fixture db: ~w(a_dep, b_dep)a
def db(a_dep, b_dep) do
# create stuff
end
end
Using normal def w/ explicit dependency list would reduce the macro based magic and make using pattern matching and the like easier, at the possible cost of verbosity.
Could possibly provide deffixture macro that compiles down to this?
That last example might not even need to use on_definition
, since we just need to build up a list of fixtures in an accumulating variable, then we can map them to functions without problem,
This could also provide a more natural place to specify scopes. Though that needs some more thoguht.
Another possible option might be exposing it as a function/macro
defmodule Example do
use ExUnitFixtures.FixtureModule
def db(a_dep, b_dep) do
end
fixture :db, :a_dep, :b_dep
# Or
fixture db: [:a_dep, :b_dep]
# Or
fixture db: ~w(a_dep, b_dep)a
end
Somewhat similar to how defoverridable
works. This might have the advantage of mostly not requiring as much macro magic, and maybe being able to work with general functions, rather than functions defined explicitly for the purpose of being fixtures....
Ok, so leaning towards an API like this:
register_fixture db, [:a_dep, :b_dep], scope: whatever
def db(a_dep, b_dep) do
end
Where register_fixture
registers the fixture with some sort of store, rather than using module attributes. If possible, this should remove the need to use
modules everywhere. We might still need some hooks on_compile
or similar to run the preprocessing, but maybe that can be done elsewhere...
Dealt with in #41
Could be worth looking into using
on_definition
instead ofdeffixture
to declare fixtures. Not sure precisely how this would work, but needs investigation.