You can use FactoryBot for non ActiveRecord models

You can use FactoryBot's initialize_with method to initialize an object any way you like which allows you to factorize any of your objects at will

FactoryBot.define do
  factory :citizen_id_image, class: CitizenIdImagePresenter do
    image_url { 'https://placehold.it/200x200' }

    initialize_with { new(image_url: image_url) }
  end
end
build(:citizen_id_image)
#=> 


6
Joe

Get our stories delivered

From us to your inbox weekly.