Managing Duplication in Factories

Once we have more than a couple of factories in our application, we want to make sure we can manage complexity and duplication. The factory_bot has several features to allow us to do just that.

Sequences

A common problem is the creation of multiple objects that require unique values. This most often happens with unique user attributes such as a login or email address. To easily create unique attributes, factory_bot allows us to define an attribute as part of a values sequence. The short version of the syntax looks like this:

Get hands-on with 1200+ tech skills courses.