Module: Spy::API
- Included in:
- Spy
- Defined in:
- lib/spy/api.rb
Instance Method Summary collapse
-
#on(*args) ⇒ Object
Initializes a new spy instance for the method.
-
#on_any_instance(spied, msg) ⇒ Object
TODO docs.
-
#restore(*args) ⇒ Object
Stops spying on the method and restores its original functionality.
Instance Method Details
#on(*args) ⇒ Object
Initializes a new spy instance for the method
With two args:
10 11 12 13 14 15 16 17 |
# File 'lib/spy/api.rb', line 10 def on(*args) case args.length when 2 spied, msg = *args return core.add_spy(spied, spied.method(msg)) end raise ArgumentError end |
#on_any_instance(spied, msg) ⇒ Object
TODO docs
20 21 22 |
# File 'lib/spy/api.rb', line 20 def on_any_instance(spied, msg) core.add_spy(spied, spied.instance_method(msg)) end |
#restore(*args) ⇒ Object
Stops spying on the method and restores its original functionality
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spy/api.rb', line 36 def restore(*args) case args.length when 1 return core.remove_all_spies if args.first == :all when 2 spied, msg = *args return core.remove_spy(spied, spied.method(msg)) when 3 spied, msg, method_type = *args return core.remove_spy(spied, spied.send(method_type, msg)) end raise ArgumentError end |