Class: Spy::Instance
- Inherits:
-
Object
- Object
- Spy::Instance
- 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
Instance Attribute Summary collapse
-
#call_history ⇒ Object
readonly
Returns the value of attribute call_history.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#spied ⇒ Object
readonly
Returns the value of attribute spied.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #before(&block) ⇒ Object
- #call_count ⇒ Object
-
#initialize(spied, original) ⇒ Instance
constructor
A new instance of Instance.
- #instead(&block) ⇒ Object
- #name ⇒ Object
- #replay_all ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #when(&block) ⇒ Object
-
#wrap(&block) ⇒ Object
Expect block to yield.
Constructor Details
#initialize(spied, original) ⇒ Instance
Returns a new instance of Instance.
14 15 16 17 18 19 20 21 22 23 24 25 |
# 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) @instead = nil end |
Instance Attribute Details
#call_history ⇒ Object (readonly)
Returns the value of attribute call_history.
12 13 14 |
# File 'lib/spy/instance.rb', line 12 def call_history @call_history end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
12 13 14 |
# File 'lib/spy/instance.rb', line 12 def original @original end |
#spied ⇒ Object (readonly)
Returns the value of attribute spied.
12 13 14 |
# File 'lib/spy/instance.rb', line 12 def spied @spied end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
12 13 14 |
# File 'lib/spy/instance.rb', line 12 def strategy @strategy end |
#visibility ⇒ Object (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
66 67 68 69 |
# File 'lib/spy/instance.rb', line 66 def after(&block) @after_callbacks << block self end |
#before(&block) ⇒ Object
61 62 63 64 |
# File 'lib/spy/instance.rb', line 61 def before(&block) @before_callbacks << block self end |
#call_count ⇒ Object
31 32 33 |
# File 'lib/spy/instance.rb', line 31 def call_count @call_history.size end |
#instead(&block) ⇒ Object
71 72 73 |
# File 'lib/spy/instance.rb', line 71 def instead(&block) @instead = block end |
#name ⇒ Object
27 28 29 |
# File 'lib/spy/instance.rb', line 27 def name @original.name end |
#replay_all ⇒ Object
35 36 37 |
# File 'lib/spy/instance.rb', line 35 def replay_all @call_history.map(&:replay) end |
#start ⇒ Object
39 40 41 42 |
# File 'lib/spy/instance.rb', line 39 def start @strategy.apply self end |
#stop ⇒ Object
44 45 46 47 |
# File 'lib/spy/instance.rb', line 44 def stop @strategy.undo self end |
#when(&block) ⇒ Object
49 50 51 52 |
# File 'lib/spy/instance.rb', line 49 def when(&block) @conditional_filters << block self end |
#wrap(&block) ⇒ Object
Expect block to yield. Call the rest of the chain when it does
56 57 58 59 |
# File 'lib/spy/instance.rb', line 56 def wrap(&block) @around_procs << block self end |