Class: FactoryGirl::Syntax::Default::DSL

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(block) ⇒ Object



48
49
50
# File 'lib/factory_girl/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_girl/syntax/default.rb', line 15

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

  FactoryGirl.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_girl/syntax/default.rb', line 44

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

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



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

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

#skip_createObject



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

def skip_create
  FactoryGirl.skip_create
end

#to_create(&block) ⇒ Object



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

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

#trait(name, &block) ⇒ Object



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

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