ttytest2 0.8.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -2
- data/Rakefile +2 -0
- data/lib/ttytest/capture.rb +2 -0
- data/lib/ttytest/matchers.rb +2 -0
- data/lib/ttytest/terminal.rb +7 -2
- data/lib/ttytest/tmux/driver.rb +1 -0
- data/lib/ttytest/tmux/session.rb +11 -4
- data/lib/ttytest/version.rb +3 -1
- data/lib/ttytest.rb +3 -0
- data/notes.txt +2 -2
- data/ttytest2.gemspec +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 000e855fe9017a84a4041ff693e8037d7ce134231699fb5e4440be428d7f068b
|
4
|
+
data.tar.gz: fac1531d712a1f276a3b861fc9f3cb1a21b6a3849433bf4bfff76ec852b39637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93ee5ba6fad1d8f44f000de98a2acd17fa7cb4d19e96dec87f2ea83a718d95db2eaf59b98d9430f8c4009d6f2808a066da31027d28b6005dd97e1906da16a783
|
7
|
+
data.tar.gz: 1d9de87f136ae70629a67e21570f325f1cd18e6ce243a0cd000b0f5217efc4222144e52ae1eaa2ba6658d2434c8a3293be83d407adda6e23e6e403432df1f94f
|
data/README.md
CHANGED
@@ -6,7 +6,10 @@ Forked from https://github.com/jhawthorn/ttytest, because I had some features I
|
|
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://
|
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
|
10
13
|
|
11
14
|
## Minimum Requirements
|
12
15
|
|
@@ -15,7 +18,8 @@ It works by running commands inside a tmux session, capturing the pane, and comp
|
|
15
18
|
|
16
19
|
## Usage
|
17
20
|
|
18
|
-
### Example
|
21
|
+
### Example Canonical CLI/Shell
|
22
|
+
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.
|
19
23
|
|
20
24
|
``` ruby
|
21
25
|
require 'ttytest'
|
@@ -36,6 +40,21 @@ TTY
|
|
36
40
|
p @tty.rows # => ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ...]
|
37
41
|
```
|
38
42
|
|
43
|
+
### Example Noncanonical CLI/Shell
|
44
|
+
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.
|
45
|
+
|
46
|
+
``` ruby
|
47
|
+
require 'ttytest'
|
48
|
+
|
49
|
+
@tty = TTYtest.new_terminal(%{PS1='$ ' /bin/noncanonical-sh}, width: 80, height: 24)
|
50
|
+
@tty.assert_row_starts_with(0, ENV['USER'])
|
51
|
+
@tty.assert_row_ends_with(0, '$')
|
52
|
+
|
53
|
+
@tty.send_keys_one_at_a_time('ls')
|
54
|
+
@tty.assert_row_ends_with(0, 'ls')
|
55
|
+
@tty.send_keys_one_at_a_time(%(\n))
|
56
|
+
```
|
57
|
+
|
39
58
|
### Assertions
|
40
59
|
|
41
60
|
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 by default).
|
data/Rakefile
CHANGED
data/lib/ttytest/capture.rb
CHANGED
data/lib/ttytest/matchers.rb
CHANGED
data/lib/ttytest/terminal.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'forwardable'
|
2
4
|
require 'ttytest/matchers'
|
3
5
|
require 'ttytest/capture'
|
@@ -17,12 +19,15 @@ module TTYtest
|
|
17
19
|
end
|
18
20
|
|
19
21
|
# @!method send_keys(*keys)
|
20
|
-
# Simulate typing keys into the terminal
|
22
|
+
# Simulate typing keys into the terminal. For canonical cli's/shells which read line by line.
|
23
|
+
# @param [String] keys keys to send to the terminal
|
24
|
+
# @!method send_keys_one_at_a_time(*keys)
|
25
|
+
# Simulate typing keys into the terminal. For noncanonical cli's/shells which read character by character.
|
21
26
|
# @param [String] keys keys to send to the terminal
|
22
27
|
# @!method capture
|
23
28
|
# Capture the current state of the terminal
|
24
29
|
# @return [Capture] instantaneous state of the terminal when called
|
25
|
-
def_delegators :@driver_terminal, :send_keys, :capture
|
30
|
+
def_delegators :@driver_terminal, :send_keys, :send_keys_one_at_a_time, :capture
|
26
31
|
|
27
32
|
# @!method rows
|
28
33
|
# @return [Array<String>]
|
data/lib/ttytest/tmux/driver.rb
CHANGED
data/lib/ttytest/tmux/session.rb
CHANGED
@@ -2,19 +2,20 @@
|
|
2
2
|
|
3
3
|
module TTYtest
|
4
4
|
module Tmux
|
5
|
+
# represents a tmux session and how to send output to the current tmux session
|
5
6
|
class Session
|
6
7
|
# @api private
|
7
8
|
def initialize(driver, name)
|
8
9
|
@driver = driver
|
9
10
|
@name = name
|
10
11
|
|
11
|
-
ObjectSpace.define_finalizer(self, self.class.finalize(driver, name))
|
12
|
+
# ObjectSpace.define_finalizer(self, self.class.finalize(driver, name))
|
12
13
|
end
|
13
14
|
|
14
15
|
# @api private
|
15
|
-
def self.finalize(driver, name)
|
16
|
-
|
17
|
-
end
|
16
|
+
# def self.finalize(driver, name)
|
17
|
+
# proc { driver.tmux(*%W[kill-session -t #{name}]) }
|
18
|
+
# end
|
18
19
|
|
19
20
|
def capture
|
20
21
|
contents = driver.tmux(*%W[capture-pane -t #{name} -p])
|
@@ -41,6 +42,12 @@ module TTYtest
|
|
41
42
|
driver.tmux(*%W[send-keys -t #{name} -l], *keys)
|
42
43
|
end
|
43
44
|
|
45
|
+
def send_keys_one_at_a_time(*keys)
|
46
|
+
keys.each do |key|
|
47
|
+
driver.tmux(*%W[send-keys -t #{name} -l], key)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
44
51
|
private
|
45
52
|
|
46
53
|
attr_reader :driver, :name
|
data/lib/ttytest/version.rb
CHANGED
data/lib/ttytest.rb
CHANGED
data/notes.txt
CHANGED
data/ttytest2.gemspec
CHANGED