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



15
16
17
# File 'lib/factory_girl/syntax/default.rb', line 15

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

Instance Method Details

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



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/factory_girl/syntax/default.rb', line 19

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)|
    factory(child_name, child_options.merge(:parent => name), &child_block)
  end
end

#sequence(name, start_value = 1, &block) ⇒ Object



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

def sequence(name, start_value = 1, &block)
  FactoryGirl.register_sequence(Sequence.new(name, start_value, &block))
end

#trait(name, &block) ⇒ Object



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

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