SeedFactory.Test (SeedFactory v0.8.0)

Copy Markdown View Source

Integrates SeedFactory with ExUnit.

Usage

Add the following line to your test modules:

use SeedFactory.Test, schema: MySeedFactorySchema

This will:

Summary

Functions

A macro for producing entities outside of test blocks.

Functions

produce(data)

(macro)
@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]])
end

Can 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)
end
produce [:company, user: [:active, :admin, as: :active_admin]]

test "my test", %{company: company, active_admin: admin} do
  assert my_function(company, admin)
end
produce org: :org1
produce org: :org2

test "my test", %{org1: org1, org2: org2} do
  assert my_function(org2, org1)
end