Class: FactoryBot::Blueprint::DSL

Inherits:
Factrey::DSL
  • Object
show all
Defined in:
lib/factory_bot/blueprint/dsl.rb

Overview

A declarative DSL for building Factrey::Blueprint. This DSL automatically recognizes factories defined in FactoryBot as types.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

Raises:

  • (NoMethodError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/factory_bot/blueprint/dsl.rb', line 19

def method_missing(name, ...)
  _autocompleted_method_names(name).each do |method_name|
    if self.class.method_defined?(method_name)
      return __send__(method_name, ...)
    elsif FactoryBot.factories.registered?(method_name)
      factory = FactoryBot.factories.find(method_name)
      self.class.add_type(self.class.type_from_factory_bot_factory(method_name, factory))
      return __send__(method_name, ...)
    end
  end

  raise NoMethodError,
        "Undefined method `#{name}' for #{self} and cannot be resolved from FactoryBot factories"
end