Keep using Factory Girl

← Back

Authors of a popular test data generator Factory Girl renamed this nice tool to a way less personal “Factory Bot”. For quite some time, I sticked to the last version of the original tool. Recently, I wrote the following little piece of code, which allows me to keep using the original name (which is referenced from the tests quite often) but with up-to-date code.


module FactoryGirl
  include FactoryBot

  def self.method_missing(m, *args, &block)
    FactoryBot.send(m, *args, &block)


if defined?(FactoryBot)
  require Rails.root.join('lib', 'factory_girl')

This doesn’t fix generators that keep putting FactoryBot into new factories. But that’s quite manageable, so I didn’t invest energy into it.

Tagged with: Ruby on Rails

Written: 2022-03-13