require 'factory_girl'
class Post
attr_accessor :title, :description
def save!
end
end
# main factory
FactoryGirl.define do
factory :post do
title "some title"
self
method(:factory).source_location
end
end
# use modify to add the trait
FactoryGirl.modify do
factory :post do
trait :with_desc do
description "some desc"
end
method(:factory).source_location
factory :described_post, traits: [:with_desc]
end
end
FactoryGirl.create :post, :with_desc
FactoryGirl.create :described_post