How can I add a function to FactoryBot globally?
问题 I have a class that extends FactoryBot to include functionality to copy Rails' .first_or_create . module FactoryBotFirstOrCreate def first(type, args) klass = type.to_s.camelize.constantize conditions = args.first.is_a?(Symbol) ? args[1] : args[0] if !conditions.empty? && conditions.is_a?(Hash) klass.where(conditions).first end end def first_or_create(type, *args) first(type, args) || create(type, *args) end def first_or_build(type, *args) first(type, args) || build(type, *args) end end I can