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.
- #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 |
# 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_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
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_count ⇒ Object
30 31 32 |
# File 'lib/spy/instance.rb', line 30 def call_count @call_history.size end |
#name ⇒ Object
26 27 28 |
# File 'lib/spy/instance.rb', line 26 def name @original.name end |
#replay_all ⇒ Object
34 35 36 |
# File 'lib/spy/instance.rb', line 34 def replay_all @call_history.map(&:replay) end |
#start ⇒ Object
38 39 40 41 |
# File 'lib/spy/instance.rb', line 38 def start @strategy.apply self end |
#stop ⇒ Object
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 |