Module: Phronomy::Testing::SchedulerHelpers
- Defined in:
- lib/phronomy/testing/scheduler_helpers.rb
Overview
RSpec helper module that provides a deterministic Runtime backed by Runtime::FakeScheduler.
Include this module in your RSpec describe/context blocks and call #with_fake_scheduler to run a block of code inside a fully synchronous, event-logged runtime.
Instance Method Summary collapse
-
#with_fake_scheduler(clock: nil) {|scheduler, clock| ... } ⇒ Object
private
Run +block+ with a Runtime that uses Runtime::FakeScheduler.
Instance Method Details
#with_fake_scheduler(clock: nil) {|scheduler, clock| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run +block+ with a Runtime that uses Runtime::FakeScheduler.
The global runtime is replaced for the duration of the block and restored afterwards, whether the block raises or not.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/phronomy/testing/scheduler_helpers.rb', line 45 def with_fake_scheduler(clock: nil) scheduler = Phronomy::Runtime::FakeScheduler.new scheduler.clock = clock if clock runtime = Phronomy::Runtime.new(scheduler: scheduler) original = Phronomy::Runtime.instance Phronomy::Runtime.instance = runtime begin yield scheduler, clock ensure Phronomy::Runtime.instance = original end end |