Method: Factory.define

Defined in:
lib/factory_girl/factory.rb

.define(name, options = {}) {|instance| ... } ⇒ Object

Defines a new factory that can be used by the build strategies (create and build) to build new objects.

Arguments:

  • name: Symbol or String A unique name used to identify this factory.

  • options: Hash

Options:

  • class: Symbol, Class, or String The class that will be used when generating instances for this factory. If not specified, the class will be guessed from the factory name.

  • parent: Symbol The parent factory. If specified, the attributes from the parent factory will be copied to the current one with an ability to override them.

  • default_strategy: Symbol The strategy that will be used by the Factory shortcut method. Defaults to :create.

Yields: Factory The newly created factory.

Yields:

  • (instance)


44
45
46
47
48
49
50
51
# File 'lib/factory_girl/factory.rb', line 44

def self.define (name, options = {})
  instance = Factory.new(name, options)
  yield(instance)
  if parent = options.delete(:parent)
    instance.inherit_from(Factory.factory_by_name(parent))
  end    
  self.factories[instance.factory_name] = instance
end