Module: ActiveFactory::API::InstanceMethods

Defined in:
lib/active_factory.rb

Overview

methods available in specs

Instance Method Summary collapse

Instance Method Details

#models(&define_graph) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_factory.rb', line 27

def models &define_graph
  not _active_factory_context_extension or raise "cannot use models twice in an example"

  context = self
  factories_hash = Define.factories_hash
  containers_hash = Hash.new { |this, name|
    factory = factories_hash[name]
    this[name] = Container.new(name, factory, context)
  }
  linking_context = LinkingContext.new factories_hash.keys, containers_hash, context
  self._active_factory_context_extension = ContextExtension.new

  linking_context.instance_eval &define_graph
  containers_hash.values.each &:before_save
  containers_hash.values.each &:save
  _active_factory_context_extension.extend_test_context containers_hash, context
  nil
end