Module: Taski::TestHelper::MockRegistry
- Defined in:
- lib/taski/test_helper/mock_registry.rb
Overview
Global registry that stores mock definitions for tests. Uses a Mutex for thread-safety when accessed from worker threads. Mocks should be reset in test setup/teardown to ensure test isolation.
Class Method Summary collapse
-
.mock_for(task_class) ⇒ MockWrapper?
Retrieves the mock wrapper for a task class, if one exists.
-
.mocks_active? ⇒ Boolean
Checks if any mocks are registered.
-
.register(task_class, mock_wrapper) ⇒ Object
Registers a mock for a task class.
-
.reset! ⇒ Object
Clears all registered mocks and resets args/env.
Class Method Details
.mock_for(task_class) ⇒ MockWrapper?
Retrieves the mock wrapper for a task class, if one exists.
26 27 28 29 30 |
# File 'lib/taski/test_helper/mock_registry.rb', line 26 def mock_for(task_class) @mutex.synchronize do @mocks[task_class] end end |
.mocks_active? ⇒ Boolean
Checks if any mocks are registered. Used for optimization to skip mock lookup in hot paths.
35 36 37 38 39 |
# File 'lib/taski/test_helper/mock_registry.rb', line 35 def mocks_active? @mutex.synchronize do !@mocks.empty? end end |
.register(task_class, mock_wrapper) ⇒ Object
Registers a mock for a task class. If a mock already exists for this class, it is replaced.
17 18 19 20 21 |
# File 'lib/taski/test_helper/mock_registry.rb', line 17 def register(task_class, mock_wrapper) @mutex.synchronize do @mocks[task_class] = mock_wrapper end end |
.reset! ⇒ Object
Clears all registered mocks and resets args/env. Should be called in test setup/teardown.
43 44 45 46 47 48 49 |
# File 'lib/taski/test_helper/mock_registry.rb', line 43 def reset! @mutex.synchronize do @mocks = {} end Taski.reset_args! Taski.reset_env! end |