Class: Mocha::InstanceMethod

Inherits:
ClassMethod show all
Defined in:
lib/mocha/instance_method.rb

Instance Attribute Summary

Attributes inherited from ClassMethod

#method, #stubbee

Instance Method Summary collapse

Methods inherited from ClassMethod

#define_new_method, #hidden_method, #initialize, #matches?, #mock, #remove_new_method, #reset_mocha, #stub, #to_s, #unstub

Constructor Details

This class inherits a constructor from Mocha::ClassMethod

Instance Method Details

#hide_original_methodObject



7
8
9
# File 'lib/mocha/instance_method.rb', line 7

def hide_original_method
  super if singleton_method?(method)
end

#method_exists?(method) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/mocha/instance_method.rb', line 15

def method_exists?(method)
  return true if stubbee.public_methods(false).include?(method)
  return true if stubbee.protected_methods(false).include?(method)
  return true if stubbee.private_methods(false).include?(method)
  return false
end

#restore_original_methodObject



11
12
13
# File 'lib/mocha/instance_method.rb', line 11

def restore_original_method
  super if singleton_method?(hidden_method)
end

#singleton_method?(method) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/mocha/instance_method.rb', line 22

def singleton_method?(method)
  __metaclass__ = stubbee.__metaclass__
  return true if __metaclass__.public_instance_methods(false).include?(method)
  return true if __metaclass__.protected_instance_methods(false).include?(method)
  return true if __metaclass__.private_instance_methods(false).include?(method)
  return false
end