Module: Kernel
- Defined in:
- lib/mack-data_factory/core_extensions/kernel.rb
Instance Method Summary collapse
-
#factories(tag, &block) ⇒ Object
Convenient routine to create an execution chain of factories.
-
#run_factories(tag) ⇒ Object
Run defined factory chain defined using factories method.
Instance Method Details
#factories(tag, &block) ⇒ Object
Convenient routine to create an execution chain of factories
Example:
factories(:foo) do
UserFactory.create(1)
UserFactory.create(2, :diff_firstname)
end
Then to execute the chains, you’ll need to call run_factories, and pass in the name of the chain you want to execute.
run_factories(:foo)
Parameters:
tag: the name of the factory chain
block: the proc to be executed later
28 29 30 31 |
# File 'lib/mack-data_factory/core_extensions/kernel.rb', line 28 def factories(tag, &block) raise "factories: block needed" if !block_given? fact_registry.add(tag, block) end |
#run_factories(tag) ⇒ Object
Run defined factory chain defined using factories method.
Parameters:
tag: the name of the factory chain to be run
39 40 41 42 43 44 |
# File 'lib/mack-data_factory/core_extensions/kernel.rb', line 39 def run_factories(tag) runners = fact_registry.registered_items[tag] return false if runners == nil runners.each { |r| r.call } return true end |