Module: RatatuiRuby::TestHelper::StyleAssertions
- Included in:
- RatatuiRuby::TestHelper
- Defined in:
- lib/ratatui_ruby/test_helper/style_assertions.rb
Overview
Assertions for verifying cell-level styling in terminal UIs.
TUI styling is invisible to plain text comparisons. Colors, bold, italic, and other modifiers define the visual hierarchy. Without style assertions, you cannot verify that your highlight is actually highlighted.
This mixin provides assertions to check foreground, background, and modifiers at specific coordinates or across entire regions.
Use it to verify selection highlights, error colors, or themed areas.
Examples
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
# Single cell
assert_cell_style(0, 0, fg: :red, modifiers: [:bold])
# Foreground color at coordinate
assert_color(:green, x: 5, y: 2)
# Entire header region
assert_area_style({ x: 0, y: 0, w: 80, h: 1 }, bg: :blue)
– SPDX-SnippetEnd ++
Instance Method Summary collapse
-
#assert_area_style(area, **attributes) ⇒ Object
Asserts that all cells in an area have the expected style.
-
#assert_bg_color(expected, x, y) ⇒ Object
(also: #assert_bg)
Asserts the background color at a coordinate.
-
#assert_bold(x, y) ⇒ Object
Asserts that a cell has the bold modifier.
-
#assert_cell_style(x, y, **expected_attributes) ⇒ Object
Asserts that a cell has the expected style attributes.
-
#assert_color(expected, x:, y:, layer: :fg) ⇒ Object
Asserts foreground or background color at a coordinate.
-
#assert_crossed_out(x, y) ⇒ Object
(also: #assert_strikethrough, #assert_strike)
Asserts that a cell has the crossed_out (strikethrough) modifier.
-
#assert_dim(x, y) ⇒ Object
Asserts that a cell has the dim modifier.
-
#assert_fg_color(expected, x, y) ⇒ Object
(also: #assert_fg)
Asserts the foreground color at a coordinate.
-
#assert_hidden(x, y) ⇒ Object
Asserts that a cell has the hidden modifier.
-
#assert_italic(x, y) ⇒ Object
Asserts that a cell has the italic modifier.
-
#assert_rapid_blink(x, y) ⇒ Object
Asserts that a cell has the rapid_blink modifier.
-
#assert_reversed(x, y) ⇒ Object
(also: #assert_inverse, #assert_inverse_video)
Asserts that a cell has the reversed (inverse video) modifier.
-
#assert_slow_blink(x, y) ⇒ Object
(also: #assert_blink)
Asserts that a cell has the slow_blink modifier.
-
#assert_underlined(x, y) ⇒ Object
(also: #assert_underline)
Asserts that a cell has the underlined modifier.
Instance Method Details
#assert_area_style(area, **attributes) ⇒ Object
Asserts that all cells in an area have the expected style.
Examples
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
header = RatatuiRuby::Layout::Rect.new(x: 0, y: 0, width: 80, height: 1)
assert_area_style(header, bg: :blue, modifiers: [:bold])
assert_area_style({ x: 0, y: 0, w: 10, h: 1 }, fg: :red)
– SPDX-SnippetEnd ++
- area
-
Rect-like object or Hash with x, y, width/w, height/h.
- attributes
-
Style attributes to verify.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 130 def assert_area_style(area, **attributes) if area.is_a?(Hash) x = area[:x] || 0 y = area[:y] || 0 w = area[:width] || area[:w] || 0 h = area[:height] || area[:h] || 0 else x = area.x y = area.y w = area.width h = area.height end (y...(y + h)).each do |row| (x...(x + w)).each do |col| assert_cell_style(col, row, **attributes) end end end |
#assert_bg_color(expected, x, y) ⇒ Object Also known as: assert_bg
Asserts the background color at a coordinate.
Convenience alias for assert_color(expected, x:, y:, layer: :bg).
Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
assert_bg_color(:blue, 0, 2)
– SPDX-SnippetEnd ++
- expected
-
Symbol, Integer, or String (hex).
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
195 196 197 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 195 def assert_bg_color(expected, x, y) assert_color(expected, x:, y:, layer: :bg) end |
#assert_bold(x, y) ⇒ Object
Asserts that a cell has the bold modifier.
Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
assert_bold(0, 2)
– SPDX-SnippetEnd ++
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
217 218 219 220 221 222 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 217 def assert_bold(x, y) cell = get_cell(x, y) modifiers = (cell.modifiers || []).map(&:to_sym) assert modifiers.include?(:bold), "Expected cell at (#{x}, #{y}) to be bold, but modifiers were #{modifiers.inspect}" end |
#assert_cell_style(x, y, **expected_attributes) ⇒ Object
Asserts that a cell has the expected style attributes.
Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
assert_cell_style(0, 0, char: "H", fg: :red)
– SPDX-SnippetEnd ++
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
- expected_attributes
-
Hash of attribute names to expected values.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 60 def assert_cell_style(x, y, **expected_attributes) cell = get_cell(x, y) expected_attributes.each do |key, value| actual_value = cell.public_send(key) if value.nil? assert_nil actual_value, "Expected cell at (#{x}, #{y}) to have #{key}=nil, but got #{actual_value.inspect}" else assert_equal value, actual_value, "Expected cell at (#{x}, #{y}) to have #{key}=#{value.inspect}, but got #{actual_value.inspect}" end end end |
#assert_color(expected, x:, y:, layer: :fg) ⇒ Object
Asserts foreground or background color at a coordinate.
Accepts symbols (:red), indexed colors (integers), or hex strings.
Examples
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
assert_color(:red, x: 10, y: 5)
assert_color(5, x: 10, y: 5, layer: :bg)
assert_color("#ff00ff", x: 10, y: 5)
– SPDX-SnippetEnd ++
- expected
-
Symbol, Integer, or String (hex).
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
- layer
-
:fg(default) or:bg.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 95 def assert_color(expected, x:, y:, layer: :fg) cell = get_cell(x, y) actual = cell.public_send(layer) # Normalize expected integer to symbol if needed (RatatuiRuby returns :indexed_N) expected_normalized = if expected.is_a?(Integer) :"indexed_#{expected}" else expected end assert_equal expected_normalized, actual, "Expected #{layer} at (#{x}, #{y}) to be #{expected.inspect}, but got #{actual.inspect}" end |
#assert_crossed_out(x, y) ⇒ Object Also known as: assert_strikethrough, assert_strike
Asserts that a cell has the crossed_out (strikethrough) modifier.
Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
assert_crossed_out(0, 2)
– SPDX-SnippetEnd ++
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
340 341 342 343 344 345 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 340 def assert_crossed_out(x, y) cell = get_cell(x, y) modifiers = (cell.modifiers || []).map(&:to_sym) assert modifiers.include?(:crossed_out), "Expected cell at (#{x}, #{y}) to be crossed_out, but modifiers were #{modifiers.inspect}" end |
#assert_dim(x, y) ⇒ Object
Asserts that a cell has the dim modifier.
Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
assert_dim(0, 2)
– SPDX-SnippetEnd ++
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
290 291 292 293 294 295 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 290 def assert_dim(x, y) cell = get_cell(x, y) modifiers = (cell.modifiers || []).map(&:to_sym) assert modifiers.include?(:dim), "Expected cell at (#{x}, #{y}) to be dim, but modifiers were #{modifiers.inspect}" end |
#assert_fg_color(expected, x, y) ⇒ Object Also known as: assert_fg
Asserts the foreground color at a coordinate.
Convenience alias for assert_color(expected, x:, y:, layer: :fg).
Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
assert_fg_color(:yellow, 0, 2)
– SPDX-SnippetEnd ++
- expected
-
Symbol, Integer, or String (hex).
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
170 171 172 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 170 def assert_fg_color(expected, x, y) assert_color(expected, x:, y:, layer: :fg) end |
#assert_hidden(x, y) ⇒ Object
Asserts that a cell has the hidden modifier.
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
354 355 356 357 358 359 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 354 def assert_hidden(x, y) cell = get_cell(x, y) modifiers = (cell.modifiers || []).map(&:to_sym) assert modifiers.include?(:hidden), "Expected cell at (#{x}, #{y}) to be hidden, but modifiers were #{modifiers.inspect}" end |
#assert_italic(x, y) ⇒ Object
Asserts that a cell has the italic modifier.
Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
assert_italic(0, 2)
– SPDX-SnippetEnd ++
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
241 242 243 244 245 246 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 241 def assert_italic(x, y) cell = get_cell(x, y) modifiers = (cell.modifiers || []).map(&:to_sym) assert modifiers.include?(:italic), "Expected cell at (#{x}, #{y}) to be italic, but modifiers were #{modifiers.inspect}" end |
#assert_rapid_blink(x, y) ⇒ Object
Asserts that a cell has the rapid_blink modifier.
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
379 380 381 382 383 384 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 379 def assert_rapid_blink(x, y) cell = get_cell(x, y) modifiers = (cell.modifiers || []).map(&:to_sym) assert modifiers.include?(:rapid_blink), "Expected cell at (#{x}, #{y}) to have rapid_blink, but modifiers were #{modifiers.inspect}" end |
#assert_reversed(x, y) ⇒ Object Also known as: assert_inverse, assert_inverse_video
Asserts that a cell has the reversed (inverse video) modifier.
Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
assert_reversed(0, 2)
– SPDX-SnippetEnd ++
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
314 315 316 317 318 319 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 314 def assert_reversed(x, y) cell = get_cell(x, y) modifiers = (cell.modifiers || []).map(&:to_sym) assert modifiers.include?(:reversed), "Expected cell at (#{x}, #{y}) to be reversed, but modifiers were #{modifiers.inspect}" end |
#assert_slow_blink(x, y) ⇒ Object Also known as: assert_blink
Asserts that a cell has the slow_blink modifier.
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
366 367 368 369 370 371 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 366 def assert_slow_blink(x, y) cell = get_cell(x, y) modifiers = (cell.modifiers || []).map(&:to_sym) assert modifiers.include?(:slow_blink), "Expected cell at (#{x}, #{y}) to have slow_blink, but modifiers were #{modifiers.inspect}" end |
#assert_underlined(x, y) ⇒ Object Also known as: assert_underline
Asserts that a cell has the underlined modifier.
Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
assert_underlined(0, 2)
– SPDX-SnippetEnd ++
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
265 266 267 268 269 270 |
# File 'lib/ratatui_ruby/test_helper/style_assertions.rb', line 265 def assert_underlined(x, y) cell = get_cell(x, y) modifiers = (cell.modifiers || []).map(&:to_sym) assert modifiers.include?(:underlined), "Expected cell at (#{x}, #{y}) to be underlined, but modifiers were #{modifiers.inspect}" end |