Module: TTYtest::Matchers
- Included in:
- Capture
- Defined in:
- lib/ttytest/matchers.rb
Constant Summary collapse
- METHODS =
public_instance_methods
Instance Method Summary collapse
-
#assert_contents(expected) ⇒ Object
(also: #assert_matches)
Asserts the full contents of the terminal.
- #assert_cursor_hidden ⇒ Object
-
#assert_cursor_position(x:, y:) ⇒ Object
Asserts that the cursor is in the expected position.
- #assert_cursor_visible ⇒ Object
-
#assert_row(row_number, expected) ⇒ Object
Asserts the contents of a single row.
Instance Method Details
#assert_contents(expected) ⇒ Object Also known as: assert_matches
Asserts the full contents of the terminal
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ttytest/matchers.rb', line 44 def assert_contents(expected) expected_rows = expected.split("\n") diff = [] matched = true rows.each_with_index do |actual_row, index| expected_row = (expected_rows[index] || "").rstrip if actual_row != expected_row diff << "-#{expected_row}" diff << "+#{actual_row}" matched = false else diff << " #{actual_row}".rstrip end end if !matched raise MatchError, "screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}" end end |
#assert_cursor_hidden ⇒ Object
35 36 37 38 39 |
# File 'lib/ttytest/matchers.rb', line 35 def assert_cursor_hidden if !cursor_hidden? raise MatchError, "expected cursor to be hidden was visible\nEntire screen:\n#{to_s}" end end |
#assert_cursor_position(x:, y:) ⇒ Object
Asserts that the cursor is in the expected position
19 20 21 22 23 24 25 |
# File 'lib/ttytest/matchers.rb', line 19 def assert_cursor_position(x:, y:) expected = [x, y] actual = [cursor_x, cursor_y] if actual != expected raise MatchError, "expected cursor to be at #{expected.inspect} but was at #{actual.inspect}\nEntire screen:\n#{to_s}" end end |
#assert_cursor_visible ⇒ Object
28 29 30 31 32 |
# File 'lib/ttytest/matchers.rb', line 28 def assert_cursor_visible if !cursor_visible? raise MatchError, "expected cursor to be visible was hidden\nEntire screen:\n#{to_s}" end end |
#assert_row(row_number, expected) ⇒ Object
Asserts the contents of a single row
7 8 9 10 11 12 13 |
# File 'lib/ttytest/matchers.rb', line 7 def assert_row(row_number, expected) expected = expected.rstrip actual = row(row_number) if actual != expected raise MatchError, "expected row #{row_number} to be #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{to_s}" end end |