Class: RatatuiRuby::Event::Sync

Inherits:
RatatuiRuby::Event show all
Defined in:
lib/ratatui_ruby/event/sync.rb

Overview

Synthetic event for synchronizing async operations in tests.

Testing async behavior is tricky. You inject an event, but results arrive later. By the time you assert, the async work may not have completed.

When a runtime (Tea, Kit) encounters this event, it should wait for all pending async operations to complete before processing the next event. This enables deterministic testing without changing production code paths.

Inject this event between user actions and assertions to ensure async results have been processed:

Example

– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++

inject_key("s")           # Triggers async command
inject_sync               # Wait for command to complete
inject_key(:q)            # Quit after seeing results
Tea.run(...)
assert_snapshots("after_s_with_results")

– SPDX-SnippetEnd ++ This is not “test mode”—it’s a real event that runtimes handle. Production apps could use it too (e.g., “ensure saves complete before quit”).

Instance Method Summary collapse

Methods inherited from RatatuiRuby::Event

#focus_gained?, #focus_lost?, #key?, #method_missing, #mouse?, #none?, #paste?, #resize?, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RatatuiRuby::Event

Instance Method Details

#deconstruct_keys(keys) ⇒ Object

Deconstructs the event for pattern matching.



47
48
49
# File 'lib/ratatui_ruby/event/sync.rb', line 47

def deconstruct_keys(keys)
  { type: :sync }
end

#sync?Boolean

Returns true for Sync events.

Returns:

  • (Boolean)


42
43
44
# File 'lib/ratatui_ruby/event/sync.rb', line 42

def sync?
  true
end