Class: Servactory::TestKit::Rspec::Helpers::MockExecutor
- Inherits:
-
Object
- Object
- Servactory::TestKit::Rspec::Helpers::MockExecutor
- Includes:
- Concerns::ErrorMessages
- Defined in:
- lib/servactory/test_kit/rspec/helpers/mock_executor.rb
Overview
Executes RSpec stubbing based on mock configurations.
## Purpose
MockExecutor translates ServiceMockConfig objects into actual RSpec stub setups using ‘allow(…).to receive(…)`. It handles single and sequential call scenarios, applying appropriate return behaviors.
## Usage
Typically used internally by ServiceMockBuilder:
“‘ruby executor = MockExecutor.new(
service_class: MyService,
configs: [config1, config2],
rspec_context: self
) executor.execute “‘
## Execution Strategies
-
**Single Config** - uses ‘and_return` or `and_raise` directly
-
**Sequential Returns** - uses ‘and_return(*values)` for multiple values
-
**Sequential with Raises** - uses ‘and_invoke(*callables)` for mixed behavior
## Architecture
Works with:
-
ServiceMockConfig - provides configuration for each stub
-
ServiceMockBuilder - creates executor with configs
-
RSpec Context - provides allow/receive/etc. methods
Instance Method Summary collapse
-
#execute ⇒ void
Executes the stub setup based on configurations.
-
#initialize(service_class:, configs:, rspec_context:) ⇒ MockExecutor
constructor
Creates a new mock executor.
Constructor Details
#initialize(service_class:, configs:, rspec_context:) ⇒ MockExecutor
Creates a new mock executor.
48 49 50 51 52 |
# File 'lib/servactory/test_kit/rspec/helpers/mock_executor.rb', line 48 def initialize(service_class:, configs:, rspec_context:) @service_class = service_class @configs = configs @rspec_context = rspec_context end |
Instance Method Details
#execute ⇒ void
This method returns an undefined value.
Executes the stub setup based on configurations.
Validates all configs first, then applies appropriate stubbing strategy (single or sequential).
61 62 63 64 65 66 67 68 69 |
# File 'lib/servactory/test_kit/rspec/helpers/mock_executor.rb', line 61 def execute validate_configs! if sequential? execute_sequential else execute_single end end |