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

+ (Object) run(block)



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

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

Instance Method Details

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



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

- (Object) initialize_with(&block)



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

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

- (Object) sequence(name, *args, &block)



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

- (Object) skip_create



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

def skip_create
  FactoryGirl.skip_create
end

- (Object) to_create(&block)



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

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

- (Object) trait(name, &block)



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

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