Module: Spectro::ClassMethods

Defined in:
lib/spectro.rb

Instance Method Summary collapse

Instance Method Details

#implements(interfaces) ⇒ Object

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 knwon rules as mocks.

Parameters:

  • interfaces ({String, Symbol=><String, Symbol>})

    hash of method names and required param names that the method supports


38
39
40
41
42
43
44
45
46
47
# File 'lib/spectro.rb', line 38

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