class FactoryGirl::Linter
Attributes
factories_to_lint[R]
factory_strategy[R]
invalid_factories[R]
Public Class Methods
new(factories, linting_strategy, factory_strategy = :create)
click to toggle source
# File lib/factory_girl/linter.rb, line 4 def initialize(factories, linting_strategy, factory_strategy = :create) @factories_to_lint = factories @linting_method = "lint_#{linting_strategy}" @factory_strategy = factory_strategy @invalid_factories = calculate_invalid_factories end
Public Instance Methods
lint!()
click to toggle source
# File lib/factory_girl/linter.rb, line 11 def lint! if invalid_factories.any? raise InvalidFactoryError, error_message end end
Private Instance Methods
calculate_invalid_factories()
click to toggle source
# File lib/factory_girl/linter.rb, line 21 def calculate_invalid_factories factories_to_lint.reduce(Hash.new([])) do |result, factory| errors = send(@linting_method, factory) result[factory] |= errors unless errors.empty? result end end
error_message()
click to toggle source
# File lib/factory_girl/linter.rb, line 85 def error_message lines = invalid_factories.map do |_factory, exceptions| exceptions.map(&:message) end.flatten <<-ERROR_MESSAGE.strip The following factories are invalid: #{lines.join("\n")} ERROR_MESSAGE end
lint_factory(factory)
click to toggle source
# File lib/factory_girl/linter.rb, line 56 def lint_factory(factory) result = [] begin FactoryGirl.public_send(factory_strategy, factory.name) rescue => error result |= [FactoryError.new(error, factory)] end result end
lint_factory_and_traits(factory)
click to toggle source
# File lib/factory_girl/linter.rb, line 79 def lint_factory_and_traits(factory) errors = lint_factory(factory) errors |= lint_traits(factory) errors end
lint_traits(factory)
click to toggle source
# File lib/factory_girl/linter.rb, line 66 def lint_traits(factory) result = [] factory.definition.defined_traits.map(&:name).each do |trait_name| begin FactoryGirl.public_send(factory_strategy, factory.name, trait_name) rescue => error result |= [FactoryTraitError.new(error, factory, trait_name)] end end result end