Module: Stendhal::Mocks::Stubbable

Included in:
Object
Defined in:
lib/stendhal/mocks/stubbable.rb

Instance Method Summary collapse

Instance Method Details

#stubs(method, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/stendhal/mocks/stubbable.rb', line 5

def stubs(method, &block)
  unless respond_to?(:"__unstubbed_#{method}")
    metaclass = (class << self;self;end)

    if respond_to? method.to_sym
      metaclass.send(:alias_method, :"__unstubbed_#{method}", method.to_sym)
      metaclass.send(:undef_method, method.to_sym)
    end

    return_value = block || Proc.new { nil }
    metaclass.send(:define_method, method.to_sym, return_value)
  end
  self
end