Module: TTYtest::Matchers
- Included in:
- Capture
- Defined in:
- lib/ttytest/matchers.rb
Constant Summary collapse
- METHODS =
public_instance_methods
Instance Method Summary collapse
- #assert_cursor_hidden ⇒ Object
- #assert_cursor_position(x:, y:) ⇒ Object
- #assert_cursor_visible ⇒ Object
- #assert_matches(expected) ⇒ Object
- #assert_row(row_number, expected) ⇒ Object
Instance Method Details
#assert_cursor_hidden ⇒ Object
24 25 26 27 28 |
# File 'lib/ttytest/matchers.rb', line 24 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
10 11 12 13 14 15 16 |
# File 'lib/ttytest/matchers.rb', line 10 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
18 19 20 21 22 |
# File 'lib/ttytest/matchers.rb', line 18 def assert_cursor_visible if !cursor_visible? raise MatchError, "expected cursor to be visible was hidden\nEntire screen:\n#{to_s}" end end |
#assert_matches(expected) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ttytest/matchers.rb', line 30 def assert_matches(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_row(row_number, expected) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/ttytest/matchers.rb', line 3 def assert_row(row_number, expected) 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 |