Module: Spy::API
- Included in:
- Spy
- Defined in:
- lib/spy/api.rb
Instance Method Summary collapse
-
#on(target, msg) ⇒ Object
Spies on calls to a method made on an object.
-
#on_any_instance(target, msg) ⇒ Object
Spies on calls to a method made on any instance of some class or module.
-
#restore(*args) ⇒ Object
Stops spying on the method and restores its original functionality.
Instance Method Details
#on(target, msg) ⇒ Object
Spies on calls to a method made on an object
9 10 11 |
# File 'lib/spy/api.rb', line 9 def on(target, msg) core.add_spy(target, target.method(msg)) end |
#on_any_instance(target, msg) ⇒ Object
Spies on calls to a method made on any instance of some class or module
18 19 20 21 |
# File 'lib/spy/api.rb', line 18 def on_any_instance(target, msg) raise ArgumentError unless target.respond_to?(:instance_method) core.add_spy(target, target.instance_method(msg)) end |
#restore(*args) ⇒ Object
Stops spying on the method and restores its original functionality
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spy/api.rb', line 35 def restore(*args) case args.length when 1 core.remove_all_spies if args.first == :all when 2 target, msg = *args core.remove_spy(target, target.method(msg)) when 3 target, msg, method_type = *args core.remove_spy(target, target.send(method_type, msg)) else raise ArgumentError end end |