module RatatuiRuby::TestHelper::StyleAssertions
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
# 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)
Public Instance Methods
Source
# 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
Asserts that all cells in an area have the expected style.
Examples
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)
- area
-
Rect-like object or Hash with x, y, width/w, height/h.
- attributes
-
Styleattributes to verify.
Source
# 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
Asserts the background color at a coordinate.
Convenience alias for assert_color(expected, x:, y:, layer: :bg).
Example
assert_bg_color(:blue, 0, 2)
- expected
-
Symbol, Integer, or String (hex).
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
Source
# 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
Asserts that a cell has the bold modifier.
Example
assert_bold(0, 2)
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
Source
# 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
Asserts that a cell has the expected style attributes.
Example
assert_cell_style(0, 0, char: "H", fg: :red)
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
- expected_attributes
-
Hash of attribute names to expected values.
Source
# 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
Asserts foreground or background color at a coordinate.
Accepts symbols (:red), indexed colors (integers), or hex strings.
Examples
assert_color(:red, x: 10, y: 5) assert_color(5, x: 10, y: 5, layer: :bg) assert_color("#ff00ff", x: 10, y: 5)
- expected
-
Symbol, Integer, or String (hex).
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
- layer
-
:fg(default) or:bg.
Source
# 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
Asserts that a cell has the crossed_out (strikethrough) modifier.
Example
assert_crossed_out(0, 2)
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
Source
# 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
Asserts that a cell has the dim modifier.
Example
assert_dim(0, 2)
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
Source
# 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
Asserts the foreground color at a coordinate.
Convenience alias for assert_color(expected, x:, y:, layer: :fg).
Example
assert_fg_color(:yellow, 0, 2)
- expected
-
Symbol, Integer, or String (hex).
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
Source
# 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
Asserts that a cell has the italic modifier.
Example
assert_italic(0, 2)
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
Source
# 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
Asserts that a cell has the rapid_blink modifier.
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
Source
# 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
Asserts that a cell has the reversed (inverse video) modifier.
Example
assert_reversed(0, 2)
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
Source
# 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
Asserts that a cell has the slow_blink modifier.
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.
Source
# 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
Asserts that a cell has the underlined modifier.
Example
assert_underlined(0, 2)
- x
-
Integer x-coordinate.
- y
-
Integer y-coordinate.