module Spectro::ClassMethods

Public Instance Methods

implements(interfaces) click to toggle source

Register the given method name supporting the given parameters.

Whenever Spectro::Config.mocks_enabled? is true it will try to cover unfulfilled specs using the known rules as mocks.

@param [{String, Symbol=><String, Symbol>}] interfaces hash of method names and required param names supported by the method

# File lib/spectro.rb, line 43
def implements interfaces
  file_path = caller.first.match(/(?:^|#{Dir.pwd}\/)([^\/].*):\d+:in .+/)[1]
  interfaces.each do |method_name, required_params|
    λ = Spectro::Database.fetch(file_path, method_name, *required_params) || Spectro::Mock.create(file_path, method_name)

    raise Spectro::Exception::UndefinedMethodDefinition.new(file_path, method_name) if λ.nil?

    self.send(:define_method, method_name, &λ)
  end
end