class Trojan::Spy
Constants
- DEFAULT_CALL_STRATEGY_VALUE
Attributes
calls[R]
Public Class Methods
new(obj, method_name)
click to toggle source
# File lib/trojan/spy.rb, line 7 def initialize(obj, method_name) @hooked = false @object = obj @method_name = method_name @original_method = @object.method(method_name) @calls = [] @call_strategy = :static_return @call_strategy_value = DEFAULT_CALL_STRATEGY_VALUE @call_strategy_index = 0 end
Public Instance Methods
hook!()
click to toggle source
# File lib/trojan/spy.rb, line 23 def hook! raise "spy has already been hooked" if hooked? @object.define_singleton_method(@method_name, stub_method) @hooked = true end
hooked?()
click to toggle source
# File lib/trojan/spy.rb, line 19 def hooked? @hooked end
unhook!()
click to toggle source
# File lib/trojan/spy.rb, line 29 def unhook! raise "spy has not been hooked yet" unless hooked? @object.define_singleton_method(@method_name, @original_method) @hooked = false end
Private Instance Methods
process_call(*args)
click to toggle source
# File lib/trojan/spy.rb, line 42 def process_call(*args) record_call(args) end
record_call(args)
click to toggle source
# File lib/trojan/spy.rb, line 46 def record_call(args) @calls << args end
stub_method()
click to toggle source
# File lib/trojan/spy.rb, line 37 def stub_method this = self proc { |*args| this.send(:process_call, *args) } end