ttytest2 0.8.3 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +55 -32
- data/lib/ttytest/constants.rb +19 -0
- data/lib/ttytest/terminal.rb +1 -1
- data/lib/ttytest/tmux/session.rb +4 -0
- data/lib/ttytest/version.rb +1 -1
- data/lib/ttytest.rb +1 -0
- data/notes.txt +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b98c6cd8789c970147b325d01c3af8e4b4eef8f32bac57aae4036b8ce3586d9
|
4
|
+
data.tar.gz: ddbfe244faedd701d96bc98ce103b49a8d825517e0664dbbea858954319290b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4862a535e862eb7fa58bc3373306ee3f82b939f5652b9b334e55acb5437358159cef2dd02d551823ff47e62625ac3b69200c526365fee2277882a617156acbd
|
7
|
+
data.tar.gz: 7ceed490dc0fb92b77ace530650a92691fdc69fa1833344b8e0000d5b1f21fe654d995b63825b5512d289c75079a83abc117d0e24c85483fda7efc5bf634bda2
|
data/README.md
CHANGED
@@ -1,15 +1,12 @@
|
|
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
|
|
9
|
-
[![Gem Version](https://badge.fury.io/rb/ttytest2.svg)](https://badge.fury.io/rb/ttytest2)
|
10
|
-
|
11
|
-
## Gem at RubyGems.org
|
12
|
-
https://rubygems.org/gems/ttytest2
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/ttytest2.svg?icon=si%3Arubygems)](https://badge.fury.io/rb/ttytest2)
|
13
10
|
|
14
11
|
## Minimum Requirements
|
15
12
|
|
@@ -18,7 +15,30 @@ https://rubygems.org/gems/ttytest2
|
|
18
15
|
|
19
16
|
## Usage
|
20
17
|
|
18
|
+
### Assertions
|
19
|
+
|
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
|
+
|
22
|
+
Available assertions:
|
23
|
+
* `assert_row(row_number, expected_text)`
|
24
|
+
* `assert_row_like(row_number, expected_text)`
|
25
|
+
* `assert_row_starts_with(row_number, expected_text)`
|
26
|
+
* `assert_row_ends_with(row_number, expected_text)`
|
27
|
+
* `assert_cursor_position(x: x, y: y)`
|
28
|
+
* `assert_cursor_visible`
|
29
|
+
* `assert_cursor_hidden`
|
30
|
+
* `assert_contents(lines_of_terminal)`
|
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)`
|
39
|
+
|
21
40
|
### Example Canonical CLI/Shell
|
41
|
+
|
22
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.
|
23
43
|
|
24
44
|
``` ruby
|
@@ -41,7 +61,10 @@ p @tty.rows # => ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ..
|
|
41
61
|
```
|
42
62
|
|
43
63
|
### Example Noncanonical CLI/Shell
|
44
|
-
|
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 />
|
45
68
|
|
46
69
|
``` ruby
|
47
70
|
require 'ttytest'
|
@@ -52,22 +75,33 @@ require 'ttytest'
|
|
52
75
|
|
53
76
|
@tty.send_keys_one_at_a_time('ls')
|
54
77
|
@tty.assert_row_ends_with(0, 'ls')
|
55
|
-
@tty.
|
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
|
56
83
|
```
|
57
84
|
|
58
|
-
###
|
85
|
+
### Constants
|
59
86
|
|
60
|
-
|
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.
|
61
88
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
104
|
+
```
|
71
105
|
|
72
106
|
## Docker
|
73
107
|
|
@@ -77,20 +111,9 @@ Easy to use from Docker. Add this to your dockerfile to get started.
|
|
77
111
|
RUN apt update && \
|
78
112
|
apt install gcc make ruby tmux -y && \
|
79
113
|
gem install ttytest2
|
80
|
-
```
|
81
|
-
|
82
|
-
## TravisCI
|
83
|
-
|
84
|
-
TTYtest can run on [TravisCI](https://travis-ci.org/), but the version of tmux made available with their default ubuntu 12.04 environment is too old. However the TravisCI ubuntu 14.04 "trusty" image provides tmux 1.8, which works great.
|
85
|
-
|
86
|
-
Ensure the following is in your `.travis.yml` (see [this project's .travis.yml](./.travis.yml) for an example)
|
87
114
|
|
88
|
-
|
89
|
-
|
90
|
-
addons:
|
91
|
-
apt:
|
92
|
-
packages:
|
93
|
-
- tmux
|
115
|
+
# add this if you have issues
|
116
|
+
# ENV RUBYOPT="-KU -E utf-8:utf-8"
|
94
117
|
```
|
95
118
|
|
96
119
|
## Contributing
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# some constants that can be used with send_keys, just to help out people creating tests
|
4
|
+
module TTYtest
|
5
|
+
BACKSPACE = 127.chr
|
6
|
+
DELETE = '^[[3~'
|
7
|
+
TAB = 9.chr
|
8
|
+
CTRLF = 6.chr
|
9
|
+
CTRLC = 3.chr
|
10
|
+
CTRLD = '\004'
|
11
|
+
ESCAPE = 27.chr
|
12
|
+
|
13
|
+
UP_ARROW = '^[[A'
|
14
|
+
DOWN_ARROW = '^[[B'
|
15
|
+
RIGHT_ARROW = '^[[C'
|
16
|
+
LEFT_ARROW = '^[[D'
|
17
|
+
|
18
|
+
CLEAR = 'clear'
|
19
|
+
end
|
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/lib/ttytest.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.5
|
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
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- lib/ttytest.rb
|
83
83
|
- lib/ttytest/capture.rb
|
84
|
+
- lib/ttytest/constants.rb
|
84
85
|
- lib/ttytest/matchers.rb
|
85
86
|
- lib/ttytest/terminal.rb
|
86
87
|
- lib/ttytest/tmux/driver.rb
|