ttytest2 0.8.6 → 0.9.0
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 +13 -9
- data/lib/ttytest/constants.rb +0 -1
- data/lib/ttytest/matchers.rb +22 -4
- data/lib/ttytest/terminal.rb +12 -2
- data/lib/ttytest/tmux/session.rb +21 -0
- 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: 9c871fc585971f615966d7797478185dd942e78b6cfcfc9324773edfd789664f
|
4
|
+
data.tar.gz: 4a7a6b509c222510918cdad040e958c09bdd653700b3a3871f087cdadf7a5c9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84d1c8b052ce38fdad9d0780774a0aae6a378b60804a156a74099e69b62f741f49b00887296e03a49030fe62c25d8bceef2b28e3a3ad2ddbd979cabbf7643b28
|
7
|
+
data.tar.gz: 4fc3e3186fe6827bb987f18e2d04aa9cfbe49c6c31f3d8a5e8ab92c6ec6f81264df11298cddbdeb70c46630f20ba056d29608f2df90549d6e3cbd25dbe7f4d29
|
data/README.md
CHANGED
@@ -20,14 +20,15 @@ It works by running commands inside a tmux session, capturing the pane, and comp
|
|
20
20
|
The main way to use TTYtest is through assertions. When called on a `TTYtest::Terminal`, each of these will be retried (for up to 2 seconds).
|
21
21
|
|
22
22
|
Available assertions:
|
23
|
-
* `assert_row(row_number, expected_text)`
|
24
|
-
* `
|
25
|
-
* `
|
26
|
-
* `
|
27
|
-
* `
|
28
|
-
* `
|
29
|
-
* `
|
30
|
-
* `
|
23
|
+
* specify row matches expected text exactly: `assert_row(row_number, expected_text) `
|
24
|
+
* specify expected position of expected text: `assert_row_at(row_number, column_start_position, column_end_position, expected_text)`
|
25
|
+
* specify row contains expected text: `assert_row_like(row_number, expected_text)`
|
26
|
+
* specify row starts with expected text: `assert_row_starts_with(row_number, expected_text)`
|
27
|
+
* specify row ends with expected text: `assert_row_ends_with(row_number, expected_text)`
|
28
|
+
* specify the current cursor position matches expected: `assert_cursor_position(x: x, y: y)`
|
29
|
+
* specify the cursor is currently visible: `assert_cursor_visible`
|
30
|
+
* specify the cursor is currently hidden: `assert_cursor_hidden`
|
31
|
+
* specify the contents of the entire terminal window: `assert_contents(lines_of_terminal)`
|
31
32
|
|
32
33
|
### Sending output
|
33
34
|
|
@@ -80,6 +81,10 @@ require 'ttytest'
|
|
80
81
|
@tty.send_keys_one_at_a_time('ps')
|
81
82
|
@tty.assert_row_ends_with(0, 'ps')
|
82
83
|
@tty.send_keys(TTYtest:NEWLINE) # can use constants instead
|
84
|
+
|
85
|
+
@tty.assert_row_starts_with(0, ENV['USER'])
|
86
|
+
@tty.assert_row_ends_with(0, '$')
|
87
|
+
@tty.send_newline # an alternative to the 2 above methods to send \n to the terminal
|
83
88
|
```
|
84
89
|
|
85
90
|
### Constants
|
@@ -88,7 +93,6 @@ There are some commonly used keys available as constants to make interacting wit
|
|
88
93
|
|
89
94
|
``` ruby
|
90
95
|
TTYtest::BACKSPACE
|
91
|
-
TTYtest::DELETE
|
92
96
|
TTYtest::TAB
|
93
97
|
TTYtest::CTRLF
|
94
98
|
TTYtest::CTRLC
|
data/lib/ttytest/constants.rb
CHANGED
data/lib/ttytest/matchers.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
module TTYtest
|
4
4
|
# Assertions for ttytest2.
|
5
5
|
module Matchers
|
6
|
-
# Asserts the contents of a single row
|
6
|
+
# Asserts the contents of a single row match the value expected
|
7
7
|
# @param [Integer] row_number the row (starting from 0) to test against
|
8
8
|
# @param [String] expected the expected value of the row. Any trailing whitespace is ignored
|
9
|
-
# @raise [MatchError] if the row doesn't match
|
9
|
+
# @raise [MatchError] if the row doesn't match exactly
|
10
10
|
def assert_row(row_number, expected)
|
11
11
|
expected = expected.rstrip
|
12
12
|
actual = row(row_number)
|
@@ -16,7 +16,25 @@ module TTYtest
|
|
16
16
|
"expected row #{row_number} to be #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}"
|
17
17
|
end
|
18
18
|
|
19
|
-
# Asserts the contents of a single row contains expected
|
19
|
+
# Asserts the contents of a single row contains the expected string at a specific position
|
20
|
+
# @param [Integer] row_number the row (starting from 0) to test against
|
21
|
+
# @param [Integer] column_start the column position to start comparing expected against
|
22
|
+
# @param [Integer] columns_end the column position to end comparing expected against
|
23
|
+
# @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
|
24
|
+
# @raise [MatchError] if the row doesn't match
|
25
|
+
def assert_row_at(row_number, column_start, column_end, expected)
|
26
|
+
expected = expected.rstrip
|
27
|
+
actual = row(row_number)
|
28
|
+
column_end += 1 if column_end.positive?
|
29
|
+
return if actual[column_start, column_end].eql?(expected)
|
30
|
+
|
31
|
+
raise MatchError,
|
32
|
+
"expected row #{row_number} to contain #{expected[column_start,
|
33
|
+
column_end]} at #{column_start}-#{column_end} and got #{actual[column_start,
|
34
|
+
column_end]}\nEntire screen:\n#{self}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Asserts the contents of a single row contains the value expected
|
20
38
|
# @param [Integer] row_number the row (starting from 0) to test against
|
21
39
|
# @param [String] expected the expected value contained in the row. Any trailing whitespace is ignored
|
22
40
|
# @raise [MatchError] if the row doesn't match
|
@@ -29,7 +47,7 @@ module TTYtest
|
|
29
47
|
"expected row #{row_number} to be like #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}"
|
30
48
|
end
|
31
49
|
|
32
|
-
# Asserts the contents of a single row
|
50
|
+
# Asserts the contents of a single row starts with expected string
|
33
51
|
# @param [Integer] row_number the row (starting from 0) to test against
|
34
52
|
# @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
|
35
53
|
# @raise [MatchError] if the row doesn't match
|
data/lib/ttytest/terminal.rb
CHANGED
@@ -21,13 +21,23 @@ module TTYtest
|
|
21
21
|
# @!method send_keys(*keys)
|
22
22
|
# Simulate typing keys into the terminal. For canonical cli's/shells which read line by line.
|
23
23
|
# @param [String] keys keys to send to the terminal
|
24
|
-
# @!method send_keys_one_at_a_time(
|
24
|
+
# @!method send_keys_one_at_a_time(keys)
|
25
25
|
# Simulate typing keys into the terminal. For noncanonical cli's/shells which read character by character.
|
26
26
|
# @param [String] keys keys to send to the terminal
|
27
|
+
# @!method send_newline
|
28
|
+
# Simulate typing enter by sending newline character to the terminal.
|
29
|
+
# @!method send_delete
|
30
|
+
# Simulate typing the delete key in the terminal.
|
31
|
+
# @!method send_backspace
|
32
|
+
# Simulate typing the backspace key in the terminal.
|
33
|
+
# @!method send_keys_exact
|
34
|
+
# Send tmux send-keys command to the terminal, such as DC or Enter, to simulate pressing that key in the terminal.
|
27
35
|
# @!method capture
|
28
36
|
# Capture the current state of the terminal
|
29
37
|
# @return [Capture] instantaneous state of the terminal when called
|
30
|
-
def_delegators :@driver_terminal,
|
38
|
+
def_delegators :@driver_terminal,
|
39
|
+
:send_keys, :send_keys_one_at_a_time, :send_newline, :send_delete, :send_backspace, :send_keys_exact,
|
40
|
+
:capture
|
31
41
|
|
32
42
|
# @!method rows
|
33
43
|
# @return [Array<String>]
|
data/lib/ttytest/tmux/session.rb
CHANGED
@@ -38,10 +38,15 @@ module TTYtest
|
|
38
38
|
)
|
39
39
|
end
|
40
40
|
|
41
|
+
# Send the array of keys as a string literal to tmux.
|
42
|
+
# Will not be interpreted as send-keys values like Enter, Escape, DC for Delete, etc.
|
43
|
+
# @param [%w()] keys the keys to send to tmux
|
41
44
|
def send_keys(*keys)
|
42
45
|
driver.tmux(*%W[send-keys -t #{name} -l], *keys)
|
43
46
|
end
|
44
47
|
|
48
|
+
# Send a string of keys one character at a time as literals to tmux.
|
49
|
+
# @param [String] keys the keys to send one at a time to tmux
|
45
50
|
def send_keys_one_at_a_time(keys)
|
46
51
|
keys.split('').each do |key|
|
47
52
|
driver.tmux(*%W[send-keys -t #{name} -l], key)
|
@@ -52,6 +57,22 @@ module TTYtest
|
|
52
57
|
driver.tmux(*%W[send-keys -t #{name} -l], %(\n))
|
53
58
|
end
|
54
59
|
|
60
|
+
def send_delete
|
61
|
+
send_keys_exact(%(DC))
|
62
|
+
end
|
63
|
+
|
64
|
+
def send_backspace
|
65
|
+
send_keys_exact(%(BSpace))
|
66
|
+
end
|
67
|
+
|
68
|
+
# Useful to send send-keys commands to tmux without sending them as a string literal.
|
69
|
+
# So you can send Escape for escape key, DC for delete, etc.
|
70
|
+
# Uses the same key bindings as bind-key as well. C-c represents Ctrl + C keys, F1 is F1 key, etc.
|
71
|
+
# @param [String] keys the keys to send to tmux
|
72
|
+
def send_keys_exact(keys)
|
73
|
+
driver.tmux(*%W[send-keys -t #{name}], keys)
|
74
|
+
end
|
75
|
+
|
55
76
|
private
|
56
77
|
|
57
78
|
attr_reader :driver, :name
|
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.
|
4
|
+
version: 0.9.0
|
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-11-
|
11
|
+
date: 2024-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|