Module: Override

Defined in:
lib/override.rb

Defined Under Namespace

Classes: ExpectationError

Instance Method Summary collapse

Instance Method Details

#expect(object, method, options) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/override.rb', line 11

def expect object, method, options
  expectation = lambda do |*params|
    unless params == options[:with]
      raise ExpectationError.new(options[:with], params)
    end
    options[:return]
  end
  override(object, method => expectation)
end

#override(object, methods) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/override.rb', line 2

def override object, methods
  methods.each do |method, result|
    result.respond_to?(:to_proc) ?
      object.meta_def(method, &result) :
      object.meta_def(method) { |*_| result }
  end
  object
end