Class: Spy::Instance

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

Defined Under Namespace

Modules: Strategy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spied, original) ⇒ Instance

Returns a new instance of Instance.



13
14
15
16
17
18
19
20
# File 'lib/spy/instance.rb', line 13

def initialize(spied, original)
  @spied = spied
  @original = original
  @visibility = extract_visibility
  @before_filters = []
  @call_count = 0
  @strategy = Strategy.factory_build(self)
end

Instance Attribute Details

#call_countObject (readonly)

Returns the value of attribute call_count.



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

def call_count
  @call_count
end

#originalObject (readonly)

Returns the value of attribute original.



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

def original
  @original
end

#spiedObject (readonly)

Returns the value of attribute spied.



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

def spied
  @spied
end

#strategyObject (readonly)

Returns the value of attribute strategy.



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

def strategy
  @strategy
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



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

def visibility
  @visibility
end

Instance Method Details

#before_call(*args) ⇒ Object



32
33
34
# File 'lib/spy/instance.rb', line 32

def before_call(*args)
  @call_count += 1 if @before_filters.all? {|f| f.before_call(*args)}
end

#startObject



22
23
24
25
# File 'lib/spy/instance.rb', line 22

def start
  @strategy.apply
  self
end

#stopObject



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

def stop
  @strategy.undo
  self
end

#when(&block) ⇒ Object



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

def when(&block)
  add_before_filter Callbacks::When.new(block)
end

#with_args(*args) ⇒ Object



36
37
38
# File 'lib/spy/instance.rb', line 36

def with_args(*args)
  add_before_filter Callbacks::WithArgs.new(*args)
end