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


48
49
50
# File 'lib/factory_bot/syntax/default.rb', line 48

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_given?

  FactoryBot.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

#initialize_with(&block) ⇒ Object


44
45
46
# File 'lib/factory_bot/syntax/default.rb', line 44

def initialize_with(&block)
  FactoryBot.initialize_with(&block)
end

#sequence(name, *args, &block) ⇒ Object


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

def sequence(name, *args, &block)
  FactoryBot.register_sequence(Sequence.new(name, *args, &block))
end

#skip_createObject


40
41
42
# File 'lib/factory_bot/syntax/default.rb', line 40

def skip_create
  FactoryBot.skip_create
end

#to_create(&block) ⇒ Object


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

def to_create(&block)
  FactoryBot.to_create(&block)
end

#trait(name, &block) ⇒ Object


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

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