Module: Spy::API

Included in:
Spy
Defined in:
lib/spy/api.rb

Instance Method Summary collapse

Instance Method Details

#on(*args) ⇒ Object

Initializes a new spy instance for the method

With two args:

Parameters:

  • receiver
    • the receiver of the message you want to spy on

  • msg
    • the message passed to the receiver that you want to spy on

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
# File 'lib/spy/api.rb', line 10

def on(*args)
  case args.length
  when 2
    return core.add_spy *(args << :method)
  end
  raise ArgumentError
end

#on_any_instance(mod, msg) ⇒ Object

TODO docs



19
20
21
# File 'lib/spy/api.rb', line 19

def on_any_instance(mod, msg)
  core.add_spy(mod, msg, :instance_method)
end

#restore(*args) ⇒ Object

Stops spying on the method and restores its original functionality

Parameters:

  • args
    • supports multiple signatures

    Spy.restore(:all)

    => stops spying on every spied message
    

    Spy.restore(receiver, msg)

    => stops spying on the given receiver and message (assumes :method)
    

    Spy.restore(reciever, msg, method_type)

    =>  stops spying on the given receiver and message of method_type
    

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/spy/api.rb', line 35

def restore(*args)
  case args.length
  when 1
    return core.remove_all_spies if args.first == :all
  when 2
    return core.remove_spy *(args << :method)
  when 3
    return core.remove_spy *args
  end
  raise ArgumentError
end