Method: MiniSpec::InstanceAPI#proxy
- Defined in:
- lib/minispec/api/instance/mocks/mocks.rb
#proxy(object, method_name) ⇒ Object
Note:
doubles and stubs will be skipped as they are already proxified
overriding given method of given object with a proxy so MiniSpec can later check whether given method was called.
if given method does not exists a NoMethodError raised
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/minispec/api/instance/mocks/mocks.rb', line 87 def proxy object, method_name # do not proxify doubles return if object.respond_to?(:__ms__double_instance) # do not proxify stubs return if (x = @__ms__stubs__originals) && (x = x[object]) && x[method_name] proxies = (@__ms__proxies[object] ||= []) return if proxies.include?(method_name) proxies << method_name # method exists and it is a singleton. # `nil?` method can be overridden only through a singleton if method_name == :nil? || object.singleton_methods.include?(method_name) return __ms__mocks__define_singleton_proxy(object, method_name) end # method exists and it is not a singleton, define a regular proxy if visibility = MiniSpec::Utils.method_visibility(object, method_name) return __ms__mocks__define_regular_proxy(object, method_name, visibility) end raise(NoMethodError, '%s does not respond to %s. Can not proxify an un-existing method.' % [ object.inspect, method_name.inspect ]) end |