Class: Impersonator::ReplayMode
- Inherits:
-
Object
- Object
- Impersonator::ReplayMode
- Includes:
- HasLogger
- Defined in:
- lib/impersonator/replay_mode.rb
Overview
The state of a recording in replay mode
Instance Attribute Summary collapse
-
#recording_path ⇒ Object
readonly
recording file path.
Instance Method Summary collapse
-
#finish ⇒ Object
Finishes the record session.
-
#initialize(recording_path) ⇒ ReplayMode
constructor
A new instance of ReplayMode.
-
#invoke(_impersonated_object, method, _args) ⇒ Object
Replays the method invocation.
-
#start ⇒ Object
Start a replay session.
Methods included from HasLogger
Constructor Details
#initialize(recording_path) ⇒ ReplayMode
Returns a new instance of ReplayMode.
10 11 12 |
# File 'lib/impersonator/replay_mode.rb', line 10 def initialize(recording_path) @recording_path = recording_path end |
Instance Attribute Details
#recording_path ⇒ Object (readonly)
recording file path
7 8 9 |
# File 'lib/impersonator/replay_mode.rb', line 7 def recording_path @recording_path end |
Instance Method Details
#finish ⇒ Object
Finishes the record session
40 41 42 43 44 45 46 |
# File 'lib/impersonator/replay_mode.rb', line 40 def finish unless @method_invocations.empty? raise Impersonator::Errors::MethodInvocationError, "Expecting #{@method_invocations.length} method invocations"\ " that didn't happen: #{@method_invocations.inspect}" end end |
#invoke(_impersonated_object, method, _args) ⇒ Object
Replays the method invocation
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/impersonator/replay_mode.rb', line 26 def invoke(_impersonated_object, method, _args) method_invocation = @method_invocations.shift unless method_invocation raise Impersonator::Errors::MethodInvocationError, 'Unexpected method invocation received:'\ "#{method}" end validate_method_signature!(method, method_invocation.method_instance) replay_block(method_invocation, method) method_invocation.return_value end |
#start ⇒ Object
Start a replay session
15 16 17 18 19 |
# File 'lib/impersonator/replay_mode.rb', line 15 def start logger.debug 'Replay mode' @replay_mode = true @method_invocations = YAML.load_file(recording_path) end |