Class: FactoryTrace::CheckUnused

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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CheckUnused

Returns a new instance of CheckUnused.

Parameters:

  • (Hash<Symbol, Set<Symbol>>)


5
6
7
# File 'lib/factory_trace/check_unused.rb', line 5

def initialize(data)
  @initial_data = data
end

Instance Method Details

#check!Array<Hash>

Returns:

  • (Array<Hash>)


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

def check!
  data = prepare(initial_data)

  output = []

  FactoryBot.factories.each do |factory|
    unless data[factory.name.to_s]
      output << {code: :unused, factory: factory}
      next
    end

    factory.defined_traits.each do |trait|
      output << {code: :unused, factory: factory, trait: trait} unless data[factory.name.to_s].include?(trait.name.to_s)
    end
  end

  FactoryBot.traits.each do |trait|
    output << {code: :unused, trait: trait} unless data['_traits'].include?(trait.name.to_s)
  end

  output
end