Module: TTYtest::Matchers
- Included in:
- Capture
- Defined in:
- lib/ttytest/matchers.rb
Overview
Assertions for ttytest2.
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 match the value expected.
-
#assert_row_at(row_number, column_start, column_end, expected) ⇒ Object
Asserts the contents of a single row contains the expected string at a specific position.
-
#assert_row_ends_with(row_number, expected) ⇒ Object
Asserts the contents of a single row end with expected.
-
#assert_row_like(row_number, expected) ⇒ Object
Asserts the contents of a single row contains the value expected.
-
#assert_row_starts_with(row_number, expected) ⇒ Object
Asserts the contents of a single row starts with expected string.
Instance Method Details
#assert_contents(expected) ⇒ Object Also known as: assert_matches
Asserts the full contents of the terminal
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ttytest/matchers.rb', line 106 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 return if matched raise MatchError, "screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}" end |
#assert_cursor_hidden ⇒ Object
97 98 99 100 101 |
# File 'lib/ttytest/matchers.rb', line 97 def assert_cursor_hidden return if cursor_hidden? raise MatchError, "expected cursor to be hidden was visible\nEntire screen:\n#{self}" end |
#assert_cursor_position(x, y) ⇒ Object
Asserts that the cursor is in the expected position
80 81 82 83 84 85 86 87 |
# File 'lib/ttytest/matchers.rb', line 80 def assert_cursor_position(x, y) expected = [x, y] actual = [cursor_x, cursor_y] return if actual == expected raise MatchError, "expected cursor to be at #{expected.inspect} but was at #{actual.inspect}\nEntire screen:\n#{self}" end |
#assert_cursor_visible ⇒ Object
90 91 92 93 94 |
# File 'lib/ttytest/matchers.rb', line 90 def assert_cursor_visible return if cursor_visible? raise MatchError, "expected cursor to be visible was hidden\nEntire screen:\n#{self}" end |
#assert_row(row_number, expected) ⇒ Object
Asserts the contents of a single row match the value expected
10 11 12 13 14 15 16 17 |
# File 'lib/ttytest/matchers.rb', line 10 def assert_row(row_number, expected) expected = expected.rstrip actual = row(row_number) return if actual == expected raise MatchError, "expected row #{row_number} to be #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}" end |
#assert_row_at(row_number, column_start, column_end, expected) ⇒ Object
Asserts the contents of a single row contains the expected string at a specific position
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ttytest/matchers.rb', line 25 def assert_row_at(row_number, column_start, column_end, expected) expected = expected.rstrip actual = row(row_number) column_end += 1 if column_end.positive? return if actual[column_start, column_end].eql?(expected) raise MatchError, "expected row #{row_number} to contain #{expected[column_start, column_end]} at #{column_start}-#{column_end} and got #{actual[column_start, column_end]}\nEntire screen:\n#{self}" end |
#assert_row_ends_with(row_number, expected) ⇒ Object
Asserts the contents of a single row end with expected
67 68 69 70 71 72 73 74 |
# File 'lib/ttytest/matchers.rb', line 67 def assert_row_ends_with(row_number, expected) expected = expected.rstrip actual = row(row_number) return if actual.end_with?(expected) raise MatchError, "expected row #{row_number} to end with #{expected.inspect} and got #{actual.inspect}\nEntire screen:\n#{self}" end |
#assert_row_like(row_number, expected) ⇒ Object
Asserts the contents of a single row contains the value expected
41 42 43 44 45 46 47 48 |
# File 'lib/ttytest/matchers.rb', line 41 def assert_row_like(row_number, expected) expected = expected.rstrip actual = row(row_number) return if actual.include?(expected) raise MatchError, "expected row #{row_number} to be like #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}" end |
#assert_row_starts_with(row_number, expected) ⇒ Object
Asserts the contents of a single row starts with expected string
54 55 56 57 58 59 60 61 |
# File 'lib/ttytest/matchers.rb', line 54 def assert_row_starts_with(row_number, expected) expected = expected.rstrip actual = row(row_number) return if actual.start_with?(expected) raise MatchError, "expected row #{row_number} to start with #{expected.inspect} and got #{actual.inspect}\nEntire screen:\n#{self}" end |