Class: Crystalball::MapGenerator::FactoryBotStrategy

Inherits:
Object
  • Object
show all
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

#root_path

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::PathFilter

#filter, #initialize

Methods included from BaseStrategy

#after_start, #before_finalize

Class Method Details

.factory_bot_constantObject



20
21
22
# File 'lib/crystalball/map_generator/factory_bot_strategy.rb', line 20

def factory_bot_constant
  defined?(::FactoryBot) ? ::FactoryBot : ::FactoryGirl
end

.factory_definitionsHash<String, String>

Map of factories to files

Returns:

  • (Hash<String, String>)


34
35
36
# File 'lib/crystalball/map_generator/factory_bot_strategy.rb', line 34

def factory_definitions
  @factory_definitions ||= {}
end

.reset_used_factoriesObject

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_factoriesArray<String>

List of factories used by current example

Returns:

  • (Array<String>)


27
28
29
# File 'lib/crystalball/map_generator/factory_bot_strategy.rb', line 27

def used_factories
  @used_factories ||= []
end

Instance Method Details

#after_registerObject



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

Parameters:

  • example_map (Crystalball::ExampleGroupMap)
    • object holding example metadata and used files

  • example (RSpec::Core::Example)
    • a RSpec example

Yields:

  • (example_map, example)


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