Class: FactoryBot::Syntax::Default::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_bot/syntax/default.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(block) ⇒ Object



36
37
38
# File 'lib/factory_bot/syntax/default.rb', line 36

def self.run(block)
  new.instance_eval(&block)
end

Instance Method Details

#factory(name, options = {}, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/factory_bot/syntax/default.rb', line 15

def factory(name, options = {}, &block)
  factory = Factory.new(name, options)
  proxy = FactoryBot::DefinitionProxy.new(factory.definition)
  proxy.instance_eval(&block) if block

  Internal.register_factory(factory)

  proxy.child_factories.each do |(child_name, child_options, child_block)|
    parent_factory = child_options.delete(:parent) || name
    factory(child_name, child_options.merge(parent: parent_factory), &child_block)
  end
end

#sequence(name) ⇒ Object



28
29
30
# File 'lib/factory_bot/syntax/default.rb', line 28

def sequence(name, ...)
  Internal.register_sequence(Sequence.new(name, ...))
end

#trait(name, &block) ⇒ Object



32
33
34
# File 'lib/factory_bot/syntax/default.rb', line 32

def trait(name, &block)
  Internal.register_trait(Trait.new(name, &block))
end