Basic Factory Definition
Explore how to define basic factories using FactoryBot in your Rails tests. Understand setting default attributes, using dynamic values, and linking factory attributes to create efficient and readable test data.
We'll cover the following...
We'll cover the following...
All the definitions of our factories go inside a call to the method FactoryBot.define, which takes a block argument. Inside that block, we can declare factories to define default data. Each factory declaration takes its own argument in which we can define default values on an attribute-by-attribute basis.
A simple example for the task builder might look like this for tasks:
and this for projects: