Class: FactoryBot::NamespacedFactories::NamespacedFactory
- Inherits:
-
Object
- Object
- FactoryBot::NamespacedFactories::NamespacedFactory
- Defined in:
- lib/factory_bot/namespaced_factories.rb
Overview
See:
- https://github.com/thoughtbot/factory_bot/issues/199
- https://github.com/thoughtbot/factory_bot/commit/652818bd1701db67ea03cd062c8259cd7fb37807
There are two main use-cases for Namespaced Factories:
1. Sharing Factories from an Engine or Gem
2. Decomposing an application using domain driven design
Instance Method Summary collapse
- #factory(name, options = {}, &block) ⇒ Object
-
#initialize(namespace, options) ⇒ NamespacedFactory
constructor
A new instance of NamespacedFactory.
Constructor Details
#initialize(namespace, options) ⇒ NamespacedFactory
Returns a new instance of NamespacedFactory.
15 16 17 18 19 20 |
# File 'lib/factory_bot/namespaced_factories.rb', line 15 def initialize(namespace, ) @namespace = namespace @options = @prefix = .fetch(:prefix, "#{namespace.to_s.underscore}_") @require_prefix = .fetch(:require_prefix, true) end |
Instance Method Details
#factory(name, options = {}, &block) ⇒ Object
22 23 24 25 |
# File 'lib/factory_bot/namespaced_factories.rb', line 22 def factory(name, = {}, &block) __dsl__.factory("#{prefix}#{name}".to_sym, .merge(class: "#{namespace}::#{name.to_s.classify}"), &block) register_without_namespace(name, , &block) end |