diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index d9599fc..3be6d42 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -1196,6 +1196,28 @@ factory :user do end ``` +### As mixins + +Traits can be defined outside of factories and used as mixins to compose shared attributes + +```ruby +FactoryBot.define do + trait :timestamps do + created_at { 8.days.ago } + updated_at { 4.days.ago } + end + + factory :user, traits: [:timestamps] do + username { "john_doe" } + end + + factory :post do + timestamps + title { "Traits rock" } + end +end +``` + ### Using traits Traits can also be passed in as a list of symbols when you construct an instance