ttytest2 0.9.11 → 0.9.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +81 -74
- data/examples/integration_tests.rb +790 -0
- data/lib/ttytest/constants.rb +2 -0
- data/lib/ttytest/matchers.rb +1 -0
- data/lib/ttytest/terminal.rb +71 -9
- data/lib/ttytest/tmux/session.rb +42 -1
- data/lib/ttytest/version.rb +1 -1
- data/notes.txt +2 -2
- metadata +3 -4
- data/examples/canonical_integration_tests.rb +0 -85
- data/examples/noncanonical_integration_tests.rb +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd614376f0369112c875543a1d8cc498b0de69dd436e6158fd6d8f06bd4ee87f
|
4
|
+
data.tar.gz: 59373cd7e5699a8e6c96a3c0071efc4164d09ddfb71365291cf4a5d086b69bd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77eb7d0d56818eaa11b3f0ac84230f5100a50bfc0ccf45c67c34a0389005b55317b5a85d23ed68f5b65c923fe8a51efe620304dcc345c7cd4cf902ff80b8e8d4
|
7
|
+
data.tar.gz: 2a3d270669408488cd1e636231b336cd62e3606d1cd20dfd267858ca3e0a544ded977ecc657df82f2833a2a2a77c9f8d422428b84715377314e6c7faf57b81e7
|
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
ttytest2 is an acceptance test framework for interactive console applications. It's like [capybara](https://github.com/teamcapybara/capybara) for the terminal.
|
4
4
|
|
5
|
-
|
5
|
+
ttytest2 is a fork and a drop-in replacement for [ttytest](https://github.com/jhawthorn/ttytest), because I had some features I needed for my own project.
|
6
6
|
|
7
|
-
It works by running commands inside a tmux session, capturing the pane, and comparing the content.
|
7
|
+
It works by running commands inside a tmux session, capturing the pane, and comparing the content to your assertions.
|
8
8
|
|
9
9
|
The assertions will wait a specified amount of time (default 2 seconds) for the expected content to appear.
|
10
10
|
|
@@ -14,17 +14,16 @@ The assertions will wait a specified amount of time (default 2 seconds) for the
|
|
14
14
|
|
15
15
|
1. [Minimum Requirements](#minimum-requirements)
|
16
16
|
2. [Usage](#usage)
|
17
|
-
3. [Example
|
18
|
-
4. [
|
19
|
-
5. [
|
20
|
-
6. [Output](#output)
|
21
|
-
7. [
|
22
|
-
8. [
|
23
|
-
9. [
|
24
|
-
10. [
|
25
|
-
11. [
|
26
|
-
12. [
|
27
|
-
13. [License](#license)
|
17
|
+
3. [Simple Example](#simple-example)
|
18
|
+
4. [Assertions](#assertions)
|
19
|
+
5. [Output](#output)
|
20
|
+
6. [Output Helpers](#output-helpers)
|
21
|
+
7. [Troubleshooting](#troubleshooting)
|
22
|
+
8. [Constants](#constants)
|
23
|
+
9. [Tips](#tips)
|
24
|
+
10. [Docker](#docker)
|
25
|
+
11. [Contributing](#contributing)
|
26
|
+
12. [License](#license)
|
28
27
|
|
29
28
|
## Minimum Requirements
|
30
29
|
|
@@ -33,29 +32,25 @@ The assertions will wait a specified amount of time (default 2 seconds) for the
|
|
33
32
|
|
34
33
|
## Usage
|
35
34
|
|
36
|
-
More documentation available at [ttytest2 docs](https://www.rubydoc.info/gems/ttytest2).
|
35
|
+
* More documentation available at [ttytest2 docs](https://www.rubydoc.info/gems/ttytest2).
|
36
|
+
* There are more examples in the examples folder.
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
### Example for Canonical CLI or Shell
|
41
|
-
|
42
|
-
Most people should use send_keys, if you are writing or working with a noncanonical shell/CLI, you will probably know it! Most shell/CLI applications are canonical.
|
38
|
+
### Simple Example
|
43
39
|
|
44
40
|
``` ruby
|
45
41
|
require 'ttytest'
|
46
|
-
|
47
|
-
@tty = TTYtest.new_terminal(%{PS1='$ ' /bin/sh}, width: 80, height: 24)
|
42
|
+
@tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 7)
|
48
43
|
@tty.assert_row(0, '$')
|
49
|
-
@tty.assert_cursor_position(
|
44
|
+
@tty.assert_cursor_position(2, 0)
|
50
45
|
|
51
|
-
@tty.
|
46
|
+
@tty.send_line('echo "Hello, world"'))
|
52
47
|
|
53
|
-
@tty.assert_contents
|
54
|
-
$ echo "Hello, world"
|
55
|
-
Hello, world
|
56
|
-
$
|
48
|
+
@tty.assert_contents <<~TTY
|
49
|
+
$ echo "Hello, world"
|
50
|
+
Hello, world
|
51
|
+
$
|
57
52
|
TTY
|
58
|
-
@tty.assert_cursor_position(
|
53
|
+
@tty.assert_cursor_position(2, 2)
|
59
54
|
|
60
55
|
@tty.assert_contents_at(0, 0, '$ echo "Hello, world"')
|
61
56
|
|
@@ -64,44 +59,20 @@ TTY
|
|
64
59
|
@tty.assert_row_starts_with(1, 'Hello')
|
65
60
|
@tty.assert_row_ends_with(1, ', world')
|
66
61
|
|
67
|
-
@tty.print_rows #
|
62
|
+
@tty.print_rows # prints out the contents of the terminal as an array:
|
63
|
+
# ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ""]
|
68
64
|
|
69
|
-
@tty.print # prints out the contents of the terminal
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
If you are working with a noncanonical shell, you need to use send_keys_one_at_a_time to have your shell/CLI process the input correctly.
|
75
|
-
|
76
|
-
Also useful if you need to send input one character at a time for whatever reason.
|
77
|
-
|
78
|
-
'Multi-character' characters like '\n' need to be sent with send-keys, though.
|
79
|
-
|
80
|
-
``` ruby
|
81
|
-
require 'ttytest'
|
82
|
-
|
83
|
-
@tty = TTYtest.new_terminal(%{PS1='$ ' /bin/noncanonical-sh}, width: 80, height: 24)
|
84
|
-
@tty.assert_row_starts_with(0, ENV['USER'])
|
85
|
-
@tty.assert_row_ends_with(0, '$')
|
86
|
-
|
87
|
-
@tty.send_keys_one_at_a_time('ls')
|
88
|
-
@tty.assert_row_ends_with(0, 'ls')
|
89
|
-
@tty.send_newline # builtins for common outputs line newline
|
90
|
-
|
91
|
-
@tty.send_keys_one_at_a_time('ps')
|
92
|
-
@tty.assert_row_ends_with(1, 'ps')
|
93
|
-
@tty.send_keys(TTYtest:NEWLINE) # can use constants instead
|
94
|
-
|
95
|
-
@tty.assert_row_starts_with(2, ENV['USER'])
|
96
|
-
@tty.assert_row_ends_with(2, '$')
|
97
|
-
@tty.send_newline
|
98
|
-
|
99
|
-
puts "\n#{@tty.capture}" # prints out the contents of the terminal, equivalent to @tty.print
|
65
|
+
@tty.print # prints out the contents of the terminal:
|
66
|
+
# $ echo "Hello, world"
|
67
|
+
# Hello, world
|
68
|
+
# $
|
100
69
|
```
|
101
70
|
|
102
71
|
### Assertions
|
103
72
|
|
104
|
-
The main way to use TTYtest is through assertions.
|
73
|
+
The main way to use TTYtest is through assertions.
|
74
|
+
|
75
|
+
Assertions will be retried for up to 2 seconds when called through TTYtest::Terminal.
|
105
76
|
|
106
77
|
Available assertions:
|
107
78
|
|
@@ -110,6 +81,7 @@ Available assertions:
|
|
110
81
|
* `assert_row_like(row_number, expected_text)`
|
111
82
|
* `assert_row_starts_with(row_number, expected_text)`
|
112
83
|
* `assert_row_ends_with(row_number, expected_text)`
|
84
|
+
* `assert_row_regexp(row_number, regexp_str)`
|
113
85
|
* `assert_cursor_position(x: x, y: y)`
|
114
86
|
* `assert_cursor_visible`
|
115
87
|
* `assert_cursor_hidden`
|
@@ -120,19 +92,35 @@ Available assertions:
|
|
120
92
|
|
121
93
|
You can send output to the terminal with the following calls.
|
122
94
|
|
123
|
-
|
124
|
-
|
125
|
-
* `
|
95
|
+
Note: Most of the time send_line has the best ergonomics.
|
96
|
+
|
97
|
+
* `send_line(line)`: simulate typing in a command in the terminal and hitting enter!
|
98
|
+
|
99
|
+
* `send_line_then_sleep(line, sleep_time)`: simulate typing in a command in the terminal and hitting enter, then wait for sleep_time seconds.
|
100
|
+
|
101
|
+
* `send_lines(lines)`: for each line in lines, simulate sending the line and hitting enter.
|
102
|
+
|
103
|
+
* `send_lines_then_sleep(lines, sleep_time)`: for each line in lines, simulate sending the line and hitting enter. After sending all the lines, sleep for sleep_time.
|
104
|
+
|
105
|
+
* `send_line_then_sleep_and_repeat(lines, sleep_time)`: for each line in lines, simulate sending the line and hitting enter, then sleep before sending the next line.
|
106
|
+
|
107
|
+
* `send_keys(output)`: for canonical shells/CLI's (or multi-character keys for noncanonical shells/CLI's).
|
108
|
+
|
109
|
+
* `send_keys_one_at_a_time(output)`: for noncanonical shells/CLI's.
|
110
|
+
|
111
|
+
* `send_keys_exact(output)`: for sending tmux specific keys (any supported send-keys arguments like: DC for delete, Escape for ESC, etc.)
|
126
112
|
|
127
113
|
### Output Helpers
|
128
114
|
|
129
115
|
Helper functions to make sending output easier! They use the methods above under 'Sending Output' section under the hood.
|
130
116
|
|
131
|
-
* `send_newline` # equivalent to @tty.send_keys(%(\n))
|
117
|
+
* `send_newline` # simulate hitting enter, equivalent to @tty.send_keys(%(\n))
|
132
118
|
* `send_newlines(number_of_times)` # equivalent to calling send_newline number_of_times
|
133
|
-
* `
|
119
|
+
* `send_enter` # alias for send_newline
|
120
|
+
* `send_enters(number_of_times)` # alias for send_newlines
|
121
|
+
* `send_backspace` # simulate hitting backspace, equivalent to @tty.send_keys(TTYtest::BACKSPACE)
|
134
122
|
* `send_backspaces(number_of_times)` # equivalent to calling send_backspace number_of_times
|
135
|
-
* `send_delete` # equivalent to calling send_keys_exact(%(DC))
|
123
|
+
* `send_delete` # simulate hitting delete, equivalent to calling send_keys_exact(%(DC))
|
136
124
|
* `send_deletes` # equivalent to calling send_delete number_of_times
|
137
125
|
* `send_right_arrow`
|
138
126
|
* `send_right_arrows(number_of_times)`
|
@@ -145,6 +133,8 @@ Helper functions to make sending output easier! They use the methods above under
|
|
145
133
|
* `send_home` # simulate pressing the Home key
|
146
134
|
* `send_end` # simulate pressing the End key
|
147
135
|
* `send_clear` # clear the screen by sending clear ascii code
|
136
|
+
* `send_escape`
|
137
|
+
* `send_escapes`
|
148
138
|
|
149
139
|
### F keys?
|
150
140
|
|
@@ -180,15 +170,24 @@ You can configure max wait time as shown below.
|
|
180
170
|
You can use the method rows to get all rows of the terminal as an array, of use the method capture to get the contents of the terminal window. This can be useful when troubleshooting.
|
181
171
|
|
182
172
|
``` ruby
|
183
|
-
@tty = TTYtest
|
173
|
+
@tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 7)
|
174
|
+
@tty.send_line('echo "Hello, world"'))
|
184
175
|
|
185
176
|
# you can use @tty.rows to access the entire pane, split by line into an array.
|
186
|
-
|
187
|
-
|
177
|
+
@tty.print_rows # prints out the contents of the terminal as an array:
|
178
|
+
# ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ""]
|
179
|
+
|
180
|
+
# if you want to programatically access the rows, you can do so using @tty.rows
|
181
|
+
p @tty.rows # is equivalent to above statement @tty.print_rows
|
188
182
|
|
189
183
|
# you can use @tty.capture to access the entire pane.
|
190
|
-
|
191
|
-
|
184
|
+
@tty.print # prints out the contents of the terminal:
|
185
|
+
# $ echo "Hello, world"
|
186
|
+
# Hello, world
|
187
|
+
# $
|
188
|
+
|
189
|
+
# if you want to programatically access the entire pane, you can do so using @tty.capture
|
190
|
+
p "\n#{@tty.capture}" # is equivalent to above statement @tty.print
|
192
191
|
```
|
193
192
|
|
194
193
|
### Constants
|
@@ -196,6 +195,8 @@ p "\n#{@tty.capture}" # prints out the contents of the terminal
|
|
196
195
|
There are some commonly used keys available as constants to make interacting with your shell/CLI easy.
|
197
196
|
|
198
197
|
``` ruby
|
198
|
+
TTYtest::CTRLA
|
199
|
+
TTYtest::CTRLB
|
199
200
|
TTYtest::CTRLC
|
200
201
|
TTYtest::CTRLD
|
201
202
|
TTYtest::CTRLF
|
@@ -203,10 +204,16 @@ There are some commonly used keys available as constants to make interacting wit
|
|
203
204
|
TTYtest::BACKSPACE
|
204
205
|
TTYtest::TAB
|
205
206
|
TTYtest::NEWLINE # \n
|
206
|
-
TTYtest::
|
207
|
+
TTYtest::ENTER # \n
|
208
|
+
TTYtest::VERTICAL_TAB # \v
|
209
|
+
TTYtest::SHIFT_ENTER # \v
|
207
210
|
TTYtest::FORM_FEED # \f or New Page NP
|
211
|
+
TTYtest::CTRLL
|
208
212
|
TTYtest::CARRIAGE_RETURN # \r
|
213
|
+
TTYtest::CTRLU
|
214
|
+
TTYtest::CTRLW
|
209
215
|
TTYtest::ESCAPE # 27 decimal or ^[ or /033
|
216
|
+
TTYtest::CTRL_
|
210
217
|
TTYtest::DELETE
|
211
218
|
|
212
219
|
TTYtest::UP_ARROW
|
@@ -222,7 +229,7 @@ There are some commonly used keys available as constants to make interacting wit
|
|
222
229
|
|
223
230
|
### Tips
|
224
231
|
|
225
|
-
If you are using ttyest2 to test your CLI, using sh is easier than bash because you don't have to worry about user, current working directory, etc. as shown in the examples
|
232
|
+
If you are using ttyest2 to test your CLI, using sh is easier than bash because you don't have to worry about user, current working directory, etc. as shown in the examples.
|
226
233
|
|
227
234
|
If you are using ttytest2 to test your shell, using assertions like assert_row_like, assert_row_starts_with, and assert_row_ends_with are going to be extremely helpful, especially if trying to test your shell in different environments or using a docker container.
|
228
235
|
|