It's really bothersome to create instance of model all the time in our tests. Factory bot (used with faker) will help us to create randomized model instance created in DB for our tests. It will also creates associated models and allows us to just override what we need to test.
Nobody wants to type @my_model = MyModel.create(name: 'important', description: 'xxx', short_description: 'owi', age: 23, array_attribute: [1,2,3] …) over and over in their test. Using create(:my_model, name: 'important') is way more easier.
Why ?
It's really bothersome to create instance of model all the time in our tests. Factory bot (used with faker) will help us to create randomized model instance created in DB for our tests. It will also creates associated models and allows us to just override what we need to test.
Nobody wants to type
@my_model = MyModel.create(name: 'important', description: 'xxx', short_description: 'owi', age: 23, array_attribute: [1,2,3] …)
over and over in their test. Usingcreate(:my_model, name: 'important')
is way more easier.Must have
Reading List