ttytest2 0.8.4 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -3
- data/lib/ttytest/constants.rb +1 -2
- data/lib/ttytest/terminal.rb +1 -1
- data/lib/ttytest/tmux/session.rb +4 -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: d5813f48d629bc3029c7c486652b5badcedbbac19b4c24946f50f8aa9df579c8
|
4
|
+
data.tar.gz: 86adb037b39d0da7cdcc9920d71f1655e8864e0171ae3fabfcb7301774908102
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6fe94d8ef4c818a94b487f01efee8ab8d2c1ed828b30679eed643e4388c9e77178d00c25e761881098b47512a51f696c597a82fabfa68d9e6a569ea52b0e15e
|
7
|
+
data.tar.gz: 0ce32ed7e12445f1c9d4fee55ec2f9b5c27a3890c73a1a3a52b45c39c5c1931ebc08bcc6f04bf5e55d372a03b82e4b19a2ccfee4a487a427d52047d92f3fec84
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# ttytest2
|
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
|
+
A drop-in replacement for https://github.com/jhawthorn/ttytest, because I had some features I needed for my own project.
|
6
6
|
|
7
7
|
It works by running commands inside a tmux session, capturing the pane, and comparing the content. The assertions will wait a specified amount of time (default 2 seconds) for the expected content to appear.
|
8
8
|
|
@@ -29,8 +29,16 @@ Available assertions:
|
|
29
29
|
* `assert_cursor_hidden`
|
30
30
|
* `assert_contents(lines_of_terminal)`
|
31
31
|
|
32
|
+
### Sending output
|
33
|
+
|
34
|
+
You can send output to the terminal with the following calls.
|
35
|
+
|
36
|
+
* `send_keys(output)`
|
37
|
+
* `send_newline # equivalent to @tty.send_keys(%(\n))`
|
38
|
+
* `send_keys_one_at_a_time(output)`
|
32
39
|
|
33
40
|
### Example Canonical CLI/Shell
|
41
|
+
|
34
42
|
Most people should use send_keys, if you are writing or working with a noncanonical shell/CLI, you will probably know it. Most are canonical.
|
35
43
|
|
36
44
|
``` ruby
|
@@ -53,7 +61,10 @@ p @tty.rows # => ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ..
|
|
53
61
|
```
|
54
62
|
|
55
63
|
### Example Noncanonical CLI/Shell
|
56
|
-
|
64
|
+
|
65
|
+
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.<br /><br />
|
66
|
+
Also useful if you need to send input one character at a time for whatever reason.<br /><br />
|
67
|
+
'Multi-character' characters like '\n' need to be sent with send-keys, though.<br /><br />
|
57
68
|
|
58
69
|
``` ruby
|
59
70
|
require 'ttytest'
|
@@ -65,6 +76,31 @@ require 'ttytest'
|
|
65
76
|
@tty.send_keys_one_at_a_time('ls')
|
66
77
|
@tty.assert_row_ends_with(0, 'ls')
|
67
78
|
@tty.send_keys(%(\n)) # make sure to use send_keys for 'multi-character' characters like \n, \r, \t, etc.
|
79
|
+
|
80
|
+
@tty.send_keys_one_at_a_time('ps')
|
81
|
+
@tty.assert_row_ends_with(0, 'ps')
|
82
|
+
@tty.send_keys(TTYtest:NEWLINE) # can use constants instead
|
83
|
+
```
|
84
|
+
|
85
|
+
### Constants
|
86
|
+
|
87
|
+
There are some commonly used keys available as constants to make interacting with your shell/CLI easy. Most of them are self-evident, BACKSPACE is the same as hitting the backspace key on the keyboard.
|
88
|
+
|
89
|
+
``` ruby
|
90
|
+
TTYtest::BACKSPACE
|
91
|
+
TTYtest::DELETE
|
92
|
+
TTYtest::TAB
|
93
|
+
TTYtest::CTRLF
|
94
|
+
TTYtest::CTRLC
|
95
|
+
TTYtest::CTRLD
|
96
|
+
TTYtest::ESCAPE
|
97
|
+
|
98
|
+
TTYtest::UP_ARROW
|
99
|
+
TTYtest::DOWN_ARROW
|
100
|
+
TTYtest::RIGHT_ARROW
|
101
|
+
TTYtest::LEFT_ARROW
|
102
|
+
|
103
|
+
TTYtest::CLEAR # clear the screen
|
68
104
|
```
|
69
105
|
|
70
106
|
## Docker
|
data/lib/ttytest/constants.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# some constants that can be used with send_keys, just to help out people creating tests
|
4
|
-
# may not work with all terminal emulators
|
5
4
|
module TTYtest
|
6
5
|
BACKSPACE = 127.chr
|
6
|
+
DELETE = '^[[3~'
|
7
7
|
TAB = 9.chr
|
8
8
|
CTRLF = 6.chr
|
9
9
|
CTRLC = 3.chr
|
10
10
|
CTRLD = '\004'
|
11
11
|
ESCAPE = 27.chr
|
12
|
-
NEWLINE = '\n'
|
13
12
|
|
14
13
|
UP_ARROW = "#{ESCAPE}[A".freeze
|
15
14
|
DOWN_ARROW = "#{ESCAPE}[B".freeze
|
data/lib/ttytest/terminal.rb
CHANGED
@@ -27,7 +27,7 @@ module TTYtest
|
|
27
27
|
# @!method capture
|
28
28
|
# Capture the current state of the terminal
|
29
29
|
# @return [Capture] instantaneous state of the terminal when called
|
30
|
-
def_delegators :@driver_terminal, :send_keys, :send_keys_one_at_a_time, :capture
|
30
|
+
def_delegators :@driver_terminal, :send_keys, :send_keys_one_at_a_time, :send_newline, :capture
|
31
31
|
|
32
32
|
# @!method rows
|
33
33
|
# @return [Array<String>]
|
data/lib/ttytest/tmux/session.rb
CHANGED
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.8.
|
4
|
+
version: 0.8.6
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|