Module: TTYtest::RowAssertions
- Included in:
- Assertions
- Defined in:
- lib/ttytest/assertions/row_assertions.rb
Overview
Row Assertions for ttytest2.
Instance Method Summary collapse
-
#assert_row(row_number, expected) ⇒ Object
(also: #assert_line)
Asserts the contents of a single row match the value expected.
-
#assert_row_at(row_number, column_start, column_end, expected) ⇒ Object
(also: #assert_line_at)
Asserts the contents of a row contain the expected string at the specified position.
-
#assert_row_ends_with(row_number, expected) ⇒ Object
(also: #assert_line_ends_with)
Asserts the contents of a single row ends with expected.
-
#assert_row_is_empty(row_number) ⇒ Object
(also: #assert_line_is_empty)
Asserts the specified row is empty.
-
#assert_row_like(row_number, expected) ⇒ Object
(also: #assert_row_contains, #assert_line_contains, #assert_line_like)
Asserts the contents of a single row contains the value expected.
-
#assert_row_regexp(row_number, regexp_str) ⇒ Object
(also: #assert_line_regexp)
Asserts the contents of a single row match against the passed in regular expression.
-
#assert_row_starts_with(row_number, expected) ⇒ Object
(also: #assert_line_starts_with)
Asserts the contents of a single row starts with expected string.
-
#assert_rows_each_match_regexp(row_start, row_end, regexp_str) ⇒ Object
(also: #assert_lines_each_match_regexp)
Asserts the contents of a multiple rows each match against the passed in regular expression.
-
#assert_rows_match_regexp(row_start, row_end, regexp_str, remove_newlines: false) ⇒ Object
(also: #assert_lines_match_regexp)
Asserts the contents of multiple rows match the passed in regular expression.
Instance Method Details
#assert_row(row_number, expected) ⇒ Object Also known as: assert_line
Asserts the contents of a single row match the value expected
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ttytest/assertions/row_assertions.rb', line 10 def assert_row(row_number, expected) validate(row_number) expected = expected.rstrip actual = row(row_number) return if !actual.nil? && actual == expected raise MatchError, "expected row #{row_number} to be #{expected.inspect} but got #{get_inspection(actual)}\n Entire screen:\n#{self}" end |
#assert_row_at(row_number, column_start, column_end, expected) ⇒ Object Also known as: assert_line_at
Asserts the contents of a row contain the expected string at the specified position
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ttytest/assertions/row_assertions.rb', line 43 def assert_row_at(row_number, column_start, column_end, expected) validate(row_number) expected = expected.rstrip actual = row(row_number) column_end += 1 return if !actual.nil? && actual[column_start, column_end].eql?(expected) inspection = get_inspection_bounded(actual, column_start, column_end) raise MatchError, "expected row #{row_number} to contain #{expected} at #{column_start}-#{column_end} and got #{inspection}\nEntire screen:\n#{self}" end |
#assert_row_ends_with(row_number, expected) ⇒ Object Also known as: assert_line_ends_with
Asserts the contents of a single row ends with expected
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ttytest/assertions/row_assertions.rb', line 96 def assert_row_ends_with(row_number, expected) validate(row_number) expected = expected.rstrip actual = row(row_number) return if !actual.nil? && actual.end_with?(expected) raise MatchError, "expected row #{row_number} to end with #{expected.inspect} and got #{get_inspection(actual)}\nEntire screen:\n#{self}" end |
#assert_row_is_empty(row_number) ⇒ Object Also known as: assert_line_is_empty
Asserts the specified row is empty
26 27 28 29 30 31 32 33 34 |
# File 'lib/ttytest/assertions/row_assertions.rb', line 26 def assert_row_is_empty(row_number) validate(row_number) actual = row(row_number) return if actual == '' raise MatchError, "expected row #{row_number} to be empty but got #{get_inspection(actual)}\nEntire screen:\n#{self}" end |
#assert_row_like(row_number, expected) ⇒ Object Also known as: assert_row_contains, assert_line_contains, assert_line_like
Asserts the contents of a single row contains the value expected
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ttytest/assertions/row_assertions.rb', line 62 def assert_row_like(row_number, expected) validate(row_number) expected = expected.rstrip actual = row(row_number) return if !actual.nil? && actual.include?(expected) raise MatchError, "expected row #{row_number} to be like #{expected.inspect} but got #{get_inspection(actual)}\nEntire screen:\n#{self}" end |
#assert_row_regexp(row_number, regexp_str) ⇒ Object Also known as: assert_line_regexp
Asserts the contents of a single row match against the passed in regular expression
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ttytest/assertions/row_assertions.rb', line 112 def assert_row_regexp(row_number, regexp_str) validate(row_number) regexp = Regexp.new(regexp_str) actual = row(row_number) return if !actual.nil? && actual.match?(regexp) raise MatchError, "expected row #{row_number} to match regexp #{regexp_str} but it did not. Row value #{get_inspection(actual)}\nEntire screen:\n#{self}" end |
#assert_row_starts_with(row_number, expected) ⇒ Object Also known as: assert_line_starts_with
Asserts the contents of a single row starts with expected string
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ttytest/assertions/row_assertions.rb', line 80 def assert_row_starts_with(row_number, expected) validate(row_number) expected = expected.rstrip actual = row(row_number) return if !actual.nil? && actual.start_with?(expected) raise MatchError, "expected row #{row_number} to start with #{expected.inspect} and got #{get_inspection(actual)}\nEntire screen:\n#{self}" end |
#assert_rows_each_match_regexp(row_start, row_end, regexp_str) ⇒ Object Also known as: assert_lines_each_match_regexp
Asserts the contents of a multiple rows each match against the passed in regular expression
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ttytest/assertions/row_assertions.rb', line 129 def assert_rows_each_match_regexp(row_start, row_end, regexp_str) validate(row_end) regexp = Regexp.new(regexp_str) row_end += 1 if row_end.zero? rows.slice(row_start, row_end).each_with_index do |actual_row, index| next if !actual_row.nil? && actual_row.match?(regexp) raise MatchError, "expected row #{index} to match regexp #{regexp_str} but it did not. Row value #{get_inspection(actual_row)}\nEntire screen:\n#{self}" end end |
#assert_rows_match_regexp(row_start, row_end, regexp_str, remove_newlines: false) ⇒ Object Also known as: assert_lines_match_regexp
Asserts the contents of multiple rows match the passed in regular expression.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/ttytest/assertions/row_assertions.rb', line 149 def assert_rows_match_regexp(row_start, row_end, regexp_str, remove_newlines: false) validate(row_end) regexp = Regexp.new(regexp_str) row_end += 1 if row_end.zero? slices = rows.slice(row_start, row_end) if remove_newlines slices.each_with_index do |slice, i| slices[i] = slice.rstrip end end actual = slices.join return if !actual.nil? && actual.match?(regexp) raise MatchError, "expected rows #{row_start}-#{row_end} to match regexp #{regexp_str} but they did not. Rows value #{get_inspection(actual)}\nEntire screen:\n#{self}" end |