Class: FactoryBot::Syntax::Default::DSL
- Inherits:
-
Object
- Object
- FactoryBot::Syntax::Default::DSL
- Defined in:
- lib/factory_bot/syntax/default.rb
Class Method Summary collapse
Instance Method Summary collapse
- #factory(name, options = {}, &block) ⇒ Object
- #sequence(name) ⇒ Object
- #trait(name, &block) ⇒ Object
Class Method Details
.run(block) ⇒ Object
36 37 38 |
# File 'lib/factory_bot/syntax/default.rb', line 36 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_bot/syntax/default.rb', line 15 def factory(name, = {}, &block) factory = Factory.new(name, ) proxy = FactoryBot::DefinitionProxy.new(factory.definition) proxy.instance_eval(&block) if block Internal.register_factory(factory) proxy.child_factories.each do |(child_name, , child_block)| parent_factory = .delete(:parent) || name factory(child_name, .merge(parent: parent_factory), &child_block) end end |
#sequence(name) ⇒ Object
28 29 30 |
# File 'lib/factory_bot/syntax/default.rb', line 28 def sequence(name, ...) Internal.register_sequence(Sequence.new(name, ...)) end |
#trait(name, &block) ⇒ Object
32 33 34 |
# File 'lib/factory_bot/syntax/default.rb', line 32 def trait(name, &block) Internal.register_trait(Trait.new(name, &block)) end |