ex_machina v1.0.0 ExMachina
Defines functions for generating data
In depth examples are in the README
Summary
Functions
Builds a factory with the passed in factory_name and attrs
Builds and returns X records with the passed in factory_name and attrs
Builds and returns 2 records with the passed in factory_name and attrs
Shortcut for creating unique string values. Similar to sequence/2
Create sequences for generating unique values
Functions
Builds a factory with the passed in factory_name and attrs
Example
def user_factory do
%{name: "John Doe", admin: false}
end
# Returns %{name: "John Doe", admin: true}
build(:user, admin: true)
Builds and returns X records with the passed in factory_name and attrs
Example
# Returns a list of 3 users
build_list(3, :user)
Builds and returns 2 records with the passed in factory_name and attrs
Example
# Returns a list of 2 users
build_pair(:user)
Shortcut for creating unique string values. Similar to sequence/2
For more customization of the generated string, see ExMachina.sequence/2
Examples
def user_factory do
%User{
# Will generate "username0" then "username1", etc.
username: sequence("username")
}
end
def article_factory do
%Article{
title: sequence("Article Title")
}
end