Module: TTYtest::ScreenAssertions
- Included in:
- Assertions
- Defined in:
- lib/ttytest/assertions/screen_assertions.rb
Overview
Screen Assertions for ttytest2.
Instance Method Summary collapse
-
#assert_contents(expected) ⇒ Object
(also: #assert_matches, #assert_screen)
Asserts the full contents of the terminal.
-
#assert_contents_at(row_start, row_end, expected) ⇒ Object
(also: #assert_matches_at, #assert_rows)
Asserts the contents of the terminal at specified rows.
-
#assert_contents_empty ⇒ Object
(also: #assert_screen_empty)
Asserts the contents of the screen are empty.
-
#assert_contents_include(expected) ⇒ Object
(also: #assert_screen_includes)
Asserts the contents of the screen include the passed in string.
-
#assert_contents_match_regexp(regexp_str) ⇒ Object
(also: #assert_screen_matches_regexp)
Asserts the contents of the screen as a single string match the passed in regular expression.
Instance Method Details
#assert_contents(expected) ⇒ Object Also known as: assert_matches, assert_screen
Asserts the full contents of the terminal
9 10 11 12 13 14 15 16 |
# File 'lib/ttytest/assertions/screen_assertions.rb', line 9 def assert_contents(expected) matched, diff = get_diff(expected, rows) return if matched raise MatchError, "screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}" end |
#assert_contents_at(row_start, row_end, expected) ⇒ Object Also known as: assert_matches_at, assert_rows
Asserts the contents of the terminal at specified rows
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ttytest/assertions/screen_assertions.rb', line 25 def assert_contents_at(row_start, row_end, expected) validate(row_end) matched, diff = get_diff(expected, rows[row_start..row_end]) return if matched raise MatchError, "screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}" end |
#assert_contents_empty ⇒ Object Also known as: assert_screen_empty
Asserts the contents of the screen are empty
55 56 57 58 59 60 |
# File 'lib/ttytest/assertions/screen_assertions.rb', line 55 def assert_contents_empty return if rows.all? { |s| s.to_s.empty? } raise MatchError, "Expected screen to be empty, but found content.\nEntire screen:\n#{self}" end |
#assert_contents_include(expected) ⇒ Object Also known as: assert_screen_includes
Asserts the contents of the screen include the passed in string
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ttytest/assertions/screen_assertions.rb', line 41 def assert_contents_include(expected) found = false rows.each do |row| found = true if row.include?(expected) end return if found raise MatchError, "Expected screen contents to include #{expected}, but it was not found.\nEntire screen:\n#{self}" end |
#assert_contents_match_regexp(regexp_str) ⇒ Object Also known as: assert_screen_matches_regexp
Asserts the contents of the screen as a single string match the passed in regular expression
66 67 68 69 70 71 72 73 74 |
# File 'lib/ttytest/assertions/screen_assertions.rb', line 66 def assert_contents_match_regexp(regexp_str) regexp = Regexp.new(regexp_str) screen = capture.to_s return if !screen.nil? && screen.match?(regexp) raise MatchError, "Expected screen contents to match regexp #{regexp_str} but they did not\nEntire screen:\n#{self}" end |