Class: Crispy::CrispyInternal::Spy
- Inherits:
-
SpyBase
- Object
- Module
- SpyBase
- Crispy::CrispyInternal::Spy
show all
- Defined in:
- lib/crispy/crispy_internal/spy.rb
Constant Summary
Constants inherited
from SpyBase
Crispy::CrispyInternal::SpyBase::BLACK_LISTED_METHODS, Crispy::CrispyInternal::SpyBase::COMMON_RECEIVED_MESSAGE_METHODS_DEFINITION
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from SpyBase
#append_received_message_when_spying, #assert_symbol!, new, #redefine_wrappers, #reinitialize, #reinitialize_stubber, #restart, #stop, #stub, #update_exceptions
Constructor Details
#initialize(target, except: []) ⇒ Spy
Returns a new instance of Spy.
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/crispy/crispy_internal/spy.rb', line 14
def initialize target, except: []
spy = self
module_eval do
define_method(:__CRISPY_SPY__) { spy }
end
@received_messages = []
super
self.class.remember_to_reset_later self
end
|
Instance Attribute Details
#received_messages ⇒ Object
Returns the value of attribute received_messages.
12
13
14
|
# File 'lib/crispy/crispy_internal/spy.rb', line 12
def received_messages
@received_messages
end
|
Class Method Details
.of_target(target) ⇒ Object
36
37
38
|
# File 'lib/crispy/crispy_internal/spy.rb', line 36
def self.of_target target
(defined? target.__CRISPY_SPY__) && target.__CRISPY_SPY__
end
|
.remember_to_reset_later(spy) ⇒ Object
46
47
48
|
# File 'lib/crispy/crispy_internal/spy.rb', line 46
def self.remember_to_reset_later spy
@spies_to_reset << ::WeakRef.new(spy)
end
|
.reset_all ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/crispy/crispy_internal/spy.rb', line 50
def self.reset_all
@spies_to_reset.select! do|spy|
if alive = spy.weakref_alive?
spy.reinitialize
end
alive
end
end
|
Instance Method Details
#erase_log ⇒ Object
32
33
34
|
# File 'lib/crispy/crispy_internal/spy.rb', line 32
def erase_log
@received_messages.clear
end
|
#target_to_class(target) ⇒ Object
26
27
28
29
30
|
# File 'lib/crispy/crispy_internal/spy.rb', line 26
def target_to_class target
class << target
self
end
end
|