module RatatuiRuby::TestHelper::TestDoubles
Test doubles for view testing.
View tests verify widget rendering without a real terminal. Real frames draw to the screen. Real rects come from terminal dimensions. Mocking both by hand is tedious.
This mixin provides MockFrame to capture rendered widgets and StubRect to supply fixed dimensions.
Use them to test view logic in isolation.
Example
frame = MockFrame.new area = StubRect.new(width: 60, height: 20) MyView.new.call(state, tui, frame, area) widget = frame.rendered_widgets.first[:widget] assert_equal "Dashboard", widget.block.title
Constants
- MockFrame
-
Mock frame for view tests.
Captures widgets passed to
render_widgetfor later inspection.Example
frame = MockFrame.new View::Log.new.call(state, tui, frame, area) widget = frame.rendered_widgets.first[:widget] assert_equal "Event Log", widget.block.title
- StubRect
-
Stub rect with fixed dimensions.
- x
-
Integer left edge (default: 0).
- y
-
Integer top edge (default: 0).
- width
-
Integer width in cells (default: 80).
- height
-
Integer height in cells (default: 24).
Example
area = StubRect.new(width: 60, height: 20)