Class: FactoryTrace::Preprocessors::ExtractDefinedFixtures

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_trace/preprocessors/extract_defined_fixtures.rb

Class Method Summary collapse

Class Method Details

.call(fixture_path) ⇒ FactoryTrace::Structures::Collection

Extracts all defined fixture sets and their entries from fixture YAML files

Parameters:

  • fixture_path (String, Array<String>)

    path(s) to directories containing fixture YAML files

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/factory_trace/preprocessors/extract_defined_fixtures.rb', line 11

def self.call(fixture_path)
  collection = FactoryTrace::Structures::Collection.new

  Array(fixture_path).each do |path|
    Dir.glob(File.join(path, "**", "*.yml")).sort.each do |file|
      fixture_set_name = File.basename(file, ".yml")
      entries = parse_fixture_file(file)

      traits = entries.map do |entry_name, definition_path|
        FactoryTrace::Structures::Trait.new(entry_name, definition_path: definition_path)
      end

      factory = FactoryTrace::Structures::Factory.new(
        [fixture_set_name],
        traits,
        definition_path: "#{file}:1"
      )

      collection.add(factory)
    end
  end

  collection
end