factory
Within a FactoryBot.define block, you can define factories. Anything defined
using factory can be built using a build strategy.
The factory method takes three arguments: a required name, an optional hash
of options, and an optional block.
The name is expected to be a Symbol.
Options
:class- what class to construct. This can be either a class, or a String or Symbol (anything that responds to#to_s). By default it is either the parent's class name or the factory's name.:parent- the name of another factory that this factory should inherit from. Defaults tonil.:aliases- alternative names for this factory. Any of these names can be used with a build strategy. Defaults to the empty list.:traits- base traits that are used by default when building this factory. Defaults to the empty list.:automatically_define_enum_traits- whether to define a trait for each value of the class's enum attributes. OverridesFactoryBot.automatically_define_enum_traitsfor this factory and its children. Defaults to the parent's setting, or the global setting when there is no parent. See Enum traits.
Block
You can use the block to define your factory. Within here you have access to the following methods:
add_attributeassociationsequencetraitmethod_missingtransienttraits_for_enuminitialize_withskip_createto_createbeforeaftercallbackfactory
You can use factory inside a factory block to define a new factory with an
implied parent.