Class: Crystalball::MapGenerator::FactoryBotStrategy
- Inherits:
-
Object
- Object
- Crystalball::MapGenerator::FactoryBotStrategy
- Includes:
- BaseStrategy, Helpers::PathFilter
- Defined in:
- lib/crystalball/map_generator/factory_bot_strategy.rb,
lib/crystalball/map_generator/factory_bot_strategy/dsl_patch.rb,
lib/crystalball/map_generator/factory_bot_strategy/factory_gem_loader.rb,
lib/crystalball/map_generator/factory_bot_strategy/factory_runner_patch.rb,
lib/crystalball/map_generator/factory_bot_strategy/dsl_patch/factory_path_fetcher.rb
Overview
Map generator strategy to include list of strategies which was used in an example.
Defined Under Namespace
Modules: DSLPatch, FactoryGemLoader, FactoryRunnerPatch
Instance Attribute Summary
Attributes included from Helpers::PathFilter
Class Method Summary collapse
- .factory_bot_constant ⇒ Object
-
.factory_definitions ⇒ Hash<String, String>
Map of factories to files.
-
.reset_used_factories ⇒ Object
Reset cached list of factories.
-
.used_factories ⇒ Array<String>
List of factories used by current example.
Instance Method Summary collapse
- #after_register ⇒ Object
-
#call(example_map, example) {|example_map, example| ... } ⇒ Object
Adds factories related to the spec to the map.
Methods included from Helpers::PathFilter
Methods included from BaseStrategy
#after_start, #before_finalize
Class Method Details
.factory_bot_constant ⇒ Object
20 21 22 |
# File 'lib/crystalball/map_generator/factory_bot_strategy.rb', line 20 def factory_bot_constant defined?(::FactoryBot) ? ::FactoryBot : ::FactoryGirl end |
.factory_definitions ⇒ Hash<String, String>
Map of factories to files
34 35 36 |
# File 'lib/crystalball/map_generator/factory_bot_strategy.rb', line 34 def factory_definitions @factory_definitions ||= {} end |
.reset_used_factories ⇒ Object
Reset cached list of factories
39 40 41 |
# File 'lib/crystalball/map_generator/factory_bot_strategy.rb', line 39 def reset_used_factories @used_factories = [] end |
.used_factories ⇒ Array<String>
List of factories used by current example
27 28 29 |
# File 'lib/crystalball/map_generator/factory_bot_strategy.rb', line 27 def used_factories @used_factories ||= [] end |
Instance Method Details
#after_register ⇒ Object
44 45 46 47 |
# File 'lib/crystalball/map_generator/factory_bot_strategy.rb', line 44 def after_register DSLPatch.apply! FactoryRunnerPatch.apply! end |
#call(example_map, example) {|example_map, example| ... } ⇒ Object
Adds factories related to the spec to the map
52 53 54 55 56 |
# File 'lib/crystalball/map_generator/factory_bot_strategy.rb', line 52 def call(example_map, example) self.class.reset_used_factories yield example_map, example example_map.push(*filter(self.class.used_factories.flat_map { |f| self.class.factory_definitions[f] })) end |