Module: TCB::TestHelpers::Shared
- Included in:
- MinitestHelpers, RSpecHelpers
- Defined in:
- lib/tcb/test_helpers/shared.rb
Instance Method Summary collapse
- #poll_until(within: 1.0, interval: 0.001, &block) ⇒ Object
- #with_subscriptions(*event_classes) ⇒ Object
Instance Method Details
#poll_until(within: 1.0, interval: 0.001, &block) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/tcb/test_helpers/shared.rb', line 6 def poll_until(within: 1.0, interval: 0.001, &block) deadline = Time.now + within loop do return true if block.call return false if Time.now >= deadline sleep interval end end |
#with_subscriptions(*event_classes) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tcb/test_helpers/shared.rb', line 15 def with_subscriptions(*event_classes) captured = Hash.new { |h, k| h[k] = [] } subscriptions = event_classes.map do |event_class| TCB.config.event_bus.subscribe(event_class) do |event| captured[event_class] << event end end yield captured ensure subscriptions.each { |sub| TCB.config.event_bus.unsubscribe(sub) } end |