ttytest2 0.9.6 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/lib/ttytest/capture.rb +1 -4
- data/lib/ttytest/matchers.rb +28 -1
- data/lib/ttytest/terminal.rb +10 -4
- data/lib/ttytest/version.rb +1 -1
- data/notes.txt +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad00f4819b188050fb5882adeac6578525082d1740c3b17a4320ec56b3f68b51
|
4
|
+
data.tar.gz: bf5dcc48c03fa7ab3cbf0c4e5780e479482f68fc19c149accd4e46c39d655cb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8357acea4da5433d9131d72ab29c21a73c38f7c53140a0eff2a0ece7393eb47b2fb749b2539dee905bd4c3baa9f7aa2e502921a33a777b060cfe32568752933d
|
7
|
+
data.tar.gz: c4ecdc9782d7c1e0633dc5b3ff4579bcbac288e6cc4628a9e496ea91fe0777ab2e028896db6f398e1f2e9b66d050b2e9a04260da636dc2a1a2c7693640555ed0
|
data/README.md
CHANGED
@@ -57,6 +57,13 @@ $
|
|
57
57
|
TTY
|
58
58
|
@tty.assert_cursor_position(x: 2, y: 2)
|
59
59
|
|
60
|
+
@tty.assert_contents_at(0, 0, '$ echo "Hello, world"')
|
61
|
+
|
62
|
+
@tty.assert_row_starts_with(0, '$ echo')
|
63
|
+
@tty.assert_row_ends_with(0, '"Hello, world"')
|
64
|
+
@tty.assert_row_starts_with(1, 'Hello')
|
65
|
+
@tty.assert_row_ends_with(1, ', world')
|
66
|
+
|
60
67
|
@tty.print_rows # => ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ...]
|
61
68
|
|
62
69
|
@tty.print # prints out the contents of the terminal
|
@@ -79,16 +86,15 @@ require 'ttytest'
|
|
79
86
|
|
80
87
|
@tty.send_keys_one_at_a_time('ls')
|
81
88
|
@tty.assert_row_ends_with(0, 'ls')
|
82
|
-
@tty.
|
89
|
+
@tty.send_newline # builtins for common outputs line newline
|
83
90
|
|
84
91
|
@tty.send_keys_one_at_a_time('ps')
|
85
92
|
@tty.assert_row_ends_with(1, 'ps')
|
86
93
|
@tty.send_keys(TTYtest:NEWLINE) # can use constants instead
|
87
94
|
|
88
|
-
|
89
95
|
@tty.assert_row_starts_with(2, ENV['USER'])
|
90
96
|
@tty.assert_row_ends_with(2, '$')
|
91
|
-
@tty.send_newline
|
97
|
+
@tty.send_newline
|
92
98
|
|
93
99
|
puts "\n#{@tty.capture}" # prints out the contents of the terminal, equivalent to @tty.print
|
94
100
|
```
|
@@ -108,6 +114,7 @@ Available assertions:
|
|
108
114
|
* `assert_cursor_visible`
|
109
115
|
* `assert_cursor_hidden`
|
110
116
|
* `assert_contents(lines_of_terminal)`
|
117
|
+
* `assert_contents_at(row_start, row_end, expected_text)`
|
111
118
|
|
112
119
|
### Output
|
113
120
|
|
data/lib/ttytest/capture.rb
CHANGED
data/lib/ttytest/matchers.rb
CHANGED
@@ -25,7 +25,7 @@ module TTYtest
|
|
25
25
|
def assert_row_at(row_number, column_start, column_end, expected)
|
26
26
|
expected = expected.rstrip
|
27
27
|
actual = row(row_number)
|
28
|
-
column_end += 1
|
28
|
+
column_end += 1
|
29
29
|
return if actual[column_start, column_end].eql?(expected)
|
30
30
|
|
31
31
|
raise MatchError,
|
@@ -125,6 +125,33 @@ module TTYtest
|
|
125
125
|
end
|
126
126
|
alias assert_matches assert_contents
|
127
127
|
|
128
|
+
# Asserts the contents of the terminal at specified rows
|
129
|
+
# @param [String] expected the expected contents of the terminal at specified rows. Trailing whitespace on each line is ignored
|
130
|
+
# @raise [MatchError] if the terminal doesn't match the expected content
|
131
|
+
def assert_contents_at(row_start, row_end, expected)
|
132
|
+
expected_rows = expected.split("\n")
|
133
|
+
diff = []
|
134
|
+
matched = true
|
135
|
+
row_end += 1 if row_end.zero?
|
136
|
+
|
137
|
+
rows.slice(row_start, row_end).each_with_index do |actual_row, index|
|
138
|
+
expected_row = (expected_rows[index] || '').rstrip
|
139
|
+
if actual_row != expected_row
|
140
|
+
diff << "-#{expected_row}"
|
141
|
+
diff << "+#{actual_row}"
|
142
|
+
matched = false
|
143
|
+
else
|
144
|
+
diff << " #{actual_row}".rstrip
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
return if matched
|
149
|
+
|
150
|
+
raise MatchError,
|
151
|
+
"screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}"
|
152
|
+
end
|
153
|
+
alias assert_matches_at assert_contents_at
|
154
|
+
|
128
155
|
METHODS = public_instance_methods
|
129
156
|
end
|
130
157
|
end
|
data/lib/ttytest/terminal.rb
CHANGED
@@ -61,13 +61,15 @@ module TTYtest
|
|
61
61
|
# @param [Integer] number of times to send up arrow
|
62
62
|
# @!method send_keys_exact
|
63
63
|
# Send tmux send-keys command to the terminal, such as DC or Enter, to simulate pressing that key in the terminal.
|
64
|
+
# @!method send_home
|
65
|
+
# Simulates typing in the Home key in the terminal.
|
66
|
+
# @!method send_end
|
67
|
+
# Simulates typing in the End key in the terminal.
|
68
|
+
# @!method send_clear
|
69
|
+
# Clears the screen in the terminal using ascii clear command.
|
64
70
|
# @!method capture
|
65
71
|
# Capture the current state of the terminal
|
66
72
|
# @return [Capture] instantaneous state of the terminal when called
|
67
|
-
# @!method print
|
68
|
-
# Prints the current state of the terminal to stdout. See capture to get the raw string.
|
69
|
-
# @!method print_rows
|
70
|
-
# Prints the current state of the terminal as an array to stdout. See rows to get the raw array.
|
71
73
|
def_delegators :@driver_terminal,
|
72
74
|
:send_keys, :send_keys_one_at_a_time,
|
73
75
|
:send_newline, :send_newlines,
|
@@ -78,6 +80,10 @@ module TTYtest
|
|
78
80
|
:send_keys_exact, :send_home, :send_end, :send_clear,
|
79
81
|
:capture
|
80
82
|
|
83
|
+
# @!method print
|
84
|
+
# Prints the current state of the terminal to stdout. See capture to get the raw string.
|
85
|
+
# @!method print_rows
|
86
|
+
# Prints the current state of the terminal as an array to stdout. See rows to get the raw array.
|
81
87
|
# @!method rows
|
82
88
|
# @return [Array<String>]
|
83
89
|
# @see Capture#rows
|
data/lib/ttytest/version.rb
CHANGED
data/notes.txt
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ttytest2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Eski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|