Class: Spy::Instance

Inherits:
Object
  • Object
show all
Includes:
API::Internal
Defined in:
lib/spy/instance.rb,
lib/spy/instance/strategy.rb,
lib/spy/instance/api/internal.rb,
lib/spy/instance/strategy/wrap.rb,
lib/spy/instance/strategy/intercept.rb

Defined Under Namespace

Modules: API, Strategy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spied, original) ⇒ Instance

Returns a new instance of Instance.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/spy/instance.rb', line 14

def initialize(spied, original)
  @spied = spied
  @original = original
  @visibility = extract_visibility
  @conditional_filters = []
  @before_callbacks = []
  @after_callbacks = []
  @around_procs = []
  @call_history = []
  @strategy = Strategy.factory_build(self)
end

Instance Attribute Details

#call_historyObject (readonly)

Returns the value of attribute call_history.



12
13
14
# File 'lib/spy/instance.rb', line 12

def call_history
  @call_history
end

#originalObject (readonly)

Returns the value of attribute original.



12
13
14
# File 'lib/spy/instance.rb', line 12

def original
  @original
end

#spiedObject (readonly)

Returns the value of attribute spied.



12
13
14
# File 'lib/spy/instance.rb', line 12

def spied
  @spied
end

#strategyObject (readonly)

Returns the value of attribute strategy.



12
13
14
# File 'lib/spy/instance.rb', line 12

def strategy
  @strategy
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



12
13
14
# File 'lib/spy/instance.rb', line 12

def visibility
  @visibility
end

Instance Method Details

#after(&block) ⇒ Object



65
66
67
68
# File 'lib/spy/instance.rb', line 65

def after(&block)
  @after_callbacks << block
  self
end

#before(&block) ⇒ Object



60
61
62
63
# File 'lib/spy/instance.rb', line 60

def before(&block)
  @before_callbacks << block
  self
end

#call_countObject



30
31
32
# File 'lib/spy/instance.rb', line 30

def call_count
  @call_history.size
end

#nameObject



26
27
28
# File 'lib/spy/instance.rb', line 26

def name
  @original.name
end

#replay_allObject



34
35
36
# File 'lib/spy/instance.rb', line 34

def replay_all
  @call_history.map(&:replay)
end

#startObject



38
39
40
41
# File 'lib/spy/instance.rb', line 38

def start
  @strategy.apply
  self
end

#stopObject



43
44
45
46
# File 'lib/spy/instance.rb', line 43

def stop
  @strategy.undo
  self
end

#when(&block) ⇒ Object



48
49
50
51
# File 'lib/spy/instance.rb', line 48

def when(&block)
  @conditional_filters << block
  self
end

#wrap(&block) ⇒ Object

Expect block to yield. Call the rest of the chain when it does



55
56
57
58
# File 'lib/spy/instance.rb', line 55

def wrap(&block)
  @around_procs << block
  self
end