Module: FactoryTrace::MonkeyPatches::Default::DSL

Defined in:
lib/factory_trace/monkey_patches/dsl.rb

Instance Method Summary collapse

Instance Method Details

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



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/factory_trace/monkey_patches/dsl.rb', line 7

def factory(name, options = {}, &block)
  caller_location = options.delete(:caller_location) || Helpers::Caller.location
  factory = FactoryBot::Factory.new(name, caller_location, options)
  proxy = FactoryBot::DefinitionProxy.new(factory.definition)
  proxy.instance_eval(&block) if block

  REGISTER.register_factory(factory)

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

#trait(name, &block) ⇒ Object



21
22
23
# File 'lib/factory_trace/monkey_patches/dsl.rb', line 21

def trait(name, &block)
  REGISTER.register_trait(FactoryBot::Trait.new(name, Helpers::Caller.location, &block))
end