Class: Spy::Strategy::Intercept
- Inherits:
-
Object
- Object
- Spy::Strategy::Intercept
- Defined in:
- lib/spy/strategy/intercept.rb
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(spy) ⇒ Intercept
constructor
A new instance of Intercept.
- #undo ⇒ Object
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
#apply ⇒ Object
19 20 21 |
# File 'lib/spy/strategy/intercept.rb', line 19 def apply ReplaceMethod.call(@target, @spy, mode: :stub) end |
#undo ⇒ Object
23 24 25 |
# File 'lib/spy/strategy/intercept.rb', line 23 def undo ReplaceMethod.call(@target, @spy, remove_existing: true) end |