Basic Factory Definition
Learn to write an example for factory_bot.
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:
Press + to interact
FactoryBot.define dofactory :task dotitle { "Thing to do" }size { "1" }completed_at { "nil" }endend
and this for projects:
Press + to interact
FactoryBot.define dofactory :project doname { "Project Runway" }due_date { "1.week.from_now" }endend