Skip to content

Instantly share code, notes, and snippets.

@gap777
gap777 / action_cable_sync.rb
Last active March 20, 2026 17:53
Monkey-patch Rails ActionCable for deterministic behavior in tests
# frozen_string_literal: true
# Make ActionCable stream delivery synchronous so that Turbo broadcast_replace_to
# calls complete before Capybara assertions run in system tests.
#
# There are two async hops between broadcast_replace_to and the DOM update:
#
# Hop 1 — AsyncSubscriberMap#invoke_callback (the test adapter extends async)
# posts each subscriber callback onto the StreamEventLoop's thread pool
# ("ActionCable-streamer") via @event_loop.post { super }. This fires before

Keybase proof

I hereby claim:

  • I am gap777 on github.
  • I am gpassero (https://keybase.io/gpassero) on keybase.
  • I have a public key ASBJ9FZttPXE5OP8lfkBK77Npa5t_I3eETpcgNesZkleZgo

To claim this, I am signing this object: