Integrates SeedFactory with ExUnit.
Usage
Add the following line to your test modules:
use SeedFactory.Test, schema: MySeedFactorySchemaThis will:
- initialize the schema via
SeedFactory.init/2in asetup_allcallback - import
SeedFactoryfunctions: - import the
produce/1macro (see below)
Summary
Functions
A macro for producing entities outside of test blocks.
Functions
@spec produce( SeedFactory.entity_name() | [ SeedFactory.entity_name() | SeedFactory.rebinding_rule() | {SeedFactory.entity_name(), [trait_name :: atom() | {:as, rebind_as :: atom()}]} ] ) :: Macro.t()
A macro for producing entities outside of test blocks.
Generates a setup callback that calls SeedFactory.produce/2, so the entities
are available in all tests within the scope. Accepts the same arguments as produce/2. This:
produce [:company, user: [:active, :admin]]is equivalent to:
setup context do
produce(context, [:company, user: [:active, :admin]])
endCan only be called outside of test blocks. For producing entities inside a test,
use SeedFactory.produce/2 directly.
Examples
produce :company
test "my test", %{company: company} do
assert my_function(company)
endproduce [:company, user: [:active, :admin, as: :active_admin]]
test "my test", %{company: company, active_admin: admin} do
assert my_function(company, admin)
endproduce org: :org1
produce org: :org2
test "my test", %{org1: org1, org2: org2} do
assert my_function(org2, org1)
end