ExZample v0.6.0 ExZample.DSL View Source
Defines a domain-speficic language(DSL) to simplify the creation of your factories.
You can use this DSL by using by defining a module and adding the use
directive. For example:
defmodule MyApp.Factories do
use ExZample.DSL
alias MyApp.User
factory :user do
example do
%User{
id: 33,
first_name: "Abili"
last_name: "de bob"
}
end
end
end
It will generate the modules and the aliases manifest to be loaded when the
ex_zample
app starts. Then, to use your factories, don't forget to start
your app. For example:
# in your test_helper.exs
:ok = Application.ensure_started(:ex_zample)
This way, all factorites your defined using the ExZample.DSL
will be
loaded module.
Options
You can pass the following options to the use
directive:
scope
(default::global
), the:scope
that all aliases of factories will be stored
Link to this section Summary
Functions
Defines a module factory with helpers imported by default.
Link to this section Functions
Defines a module factory with helpers imported by default.
If you pass an atom
for factory name, such as user
, the module will be
generated with UserFactory
. If you pass a scope, like: my_app: :user
, the
module name will become MyAppUserFactory
.
The factory body has all functions from ExZample
imported. It also has access
to example
DSL helper that generates a function definition with behaviour
annotations. Taking those helpers out, everything else work as normal Elixir
module.