Class: Spy::Strategy::Intercept

Inherits:
Object
  • Object
show all
Defined in:
lib/spy/strategy/intercept.rb

Instance Method Summary collapse

Constructor Details

#initialize(spy) ⇒ Intercept

Returns a new instance of Intercept.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/spy/strategy/intercept.rb', line 6

def initialize(spy)
  @spy = spy
  @target =
    case spy.original
    when Method
      spy.spied.singleton_class
    when UnboundMethod
      spy.spied
    when FakeMethod
      spy.spied.singleton_class
    end
end

Instance Method Details

#applyObject



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

def apply
  ReplaceMethod.call(@target, @spy, mode: :stub)
end

#undoObject



23
24
25
# File 'lib/spy/strategy/intercept.rb', line 23

def undo
  ReplaceMethod.call(@target, @spy, remove_existing: true)
end