ttytest 0.2.0 → 0.3.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 +16 -13
- data/lib/ttytest.rb +4 -0
- data/lib/ttytest/capture.rb +13 -2
- data/lib/ttytest/matchers.rb +12 -0
- data/lib/ttytest/terminal.rb +11 -9
- data/lib/ttytest/tmux/session.rb +10 -8
- data/lib/ttytest/tmux/tmux.conf +1 -0
- data/lib/ttytest/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78021e6870947818ac2d9be3fe3d83fe5070662d
|
4
|
+
data.tar.gz: d3cc412b912956ef3ea44948f6a656b3bfca644f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fc3b334c3c43bbe3fe518f74ca5be4b262f60014f564443433a41fb2b503905264ff2df725379cd173729ce5fdca7638848a991a78ee6056f36c75c8c838669
|
7
|
+
data.tar.gz: 371818454cdc7df5cd7d6ceef162ddf0075ad5f6bd425122457fb0ef1e4c02e99d776c9eda2faf3adf31a01530fdbe57e04905a31f52fc216c76b6359c589df3
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
TTYtest is an integration test framework for interactive
|
1
|
+
TTYtest is an integration test framework for interactive console applications. It's like [capybara](https://github.com/teamcapybara/capybara) for the terminal.
|
2
|
+
|
3
|
+
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.
|
2
4
|
|
3
5
|
[](https://travis-ci.org/jhawthorn/ttytest)
|
4
6
|
|
@@ -10,20 +12,21 @@ TTYtest is an integration test framework for interactive tty applications. It's
|
|
10
12
|
## Usage
|
11
13
|
|
12
14
|
``` ruby
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
15
|
+
@tty = TTYtest.new_terminal(%{PS1='$ ' /bin/sh}, width: 80, height: 24)
|
16
|
+
@tty.assert_row(0, '$')
|
17
|
+
@tty.assert_cursor_position(x: 2, y: 0)
|
18
|
+
|
19
|
+
@tty.send_keys(%{echo "Hello, world"\n})
|
20
|
+
|
21
|
+
@tty.assert_row(0, '$ echo "Hello, world"')
|
22
|
+
@tty.assert_row(1, 'Hello, world')
|
23
|
+
@tty.assert_cursor_position(x: 2, y: 2)
|
24
|
+
|
25
|
+
p @tty.rows # => ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ...]
|
25
26
|
```
|
26
27
|
|
28
|
+
See also [fzy's integration test](https://github.com/jhawthorn/fzy/blob/master/test/integration/integration_test.rb) for a full example.
|
29
|
+
|
27
30
|
## TravisCI
|
28
31
|
|
29
32
|
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.
|
data/lib/ttytest.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'forwardable'
|
1
2
|
require 'ttytest/tmux/driver'
|
2
3
|
require 'ttytest/tmux/session'
|
3
4
|
|
@@ -5,6 +6,9 @@ module TTYtest
|
|
5
6
|
class << self
|
6
7
|
attr_accessor :driver
|
7
8
|
attr_accessor :default_max_wait_time
|
9
|
+
|
10
|
+
extend Forwardable
|
11
|
+
def_delegators :driver, :new_terminal
|
8
12
|
end
|
9
13
|
|
10
14
|
class MatchError < StandardError; end
|
data/lib/ttytest/capture.rb
CHANGED
@@ -2,14 +2,17 @@ module TTYtest
|
|
2
2
|
class Capture
|
3
3
|
include TTYtest::Matchers
|
4
4
|
|
5
|
-
attr_reader :cursor_x, :cursor_y
|
5
|
+
attr_reader :cursor_x, :cursor_y
|
6
|
+
attr_reader :width, :height
|
6
7
|
|
7
|
-
def initialize(contents, cursor_x: 0, cursor_y: 0, cursor_visible: true)
|
8
|
+
def initialize(contents, cursor_x: 0, cursor_y: 0, width: nil, height: nil, cursor_visible: true)
|
8
9
|
@rows = (contents+"\nEND").split("\n")[0...-1].map do |row|
|
9
10
|
row || ""
|
10
11
|
end
|
11
12
|
@cursor_x = cursor_x
|
12
13
|
@cursor_y = cursor_y
|
14
|
+
@width = width
|
15
|
+
@height = height
|
13
16
|
@cursor_visible = cursor_visible
|
14
17
|
end
|
15
18
|
|
@@ -25,6 +28,14 @@ module TTYtest
|
|
25
28
|
rows[row]
|
26
29
|
end
|
27
30
|
|
31
|
+
def cursor_visible?
|
32
|
+
@cursor_visible
|
33
|
+
end
|
34
|
+
|
35
|
+
def cursor_hidden?
|
36
|
+
!cursor_visible?
|
37
|
+
end
|
38
|
+
|
28
39
|
def capture
|
29
40
|
self
|
30
41
|
end
|
data/lib/ttytest/matchers.rb
CHANGED
@@ -15,6 +15,18 @@ module TTYtest
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def assert_cursor_visible
|
19
|
+
if !cursor_visible?
|
20
|
+
raise MatchError, "expected cursor to be visible was hidden\nEntire screen:\n#{to_s}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_cursor_hidden
|
25
|
+
if !cursor_hidden?
|
26
|
+
raise MatchError, "expected cursor to be hidden was visible\nEntire screen:\n#{to_s}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
18
30
|
METHODS = public_instance_methods
|
19
31
|
end
|
20
32
|
end
|
data/lib/ttytest/terminal.rb
CHANGED
@@ -16,7 +16,17 @@ module TTYtest
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def_delegators :@driver_terminal, :send_keys, :send_raw, :capture
|
19
|
-
def_delegators :capture, :rows, :row, :cursor_position
|
19
|
+
def_delegators :capture, :rows, :row, :cursor_position, :width, :height, :cursor_visible?, :cursor_hidden?
|
20
|
+
|
21
|
+
TTYtest::Matchers::METHODS.each do |matcher_name|
|
22
|
+
define_method matcher_name do |*args|
|
23
|
+
synchronize do
|
24
|
+
capture.public_send(matcher_name, *args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
20
30
|
|
21
31
|
def synchronize(seconds=max_wait_time)
|
22
32
|
start_time = Time.now
|
@@ -28,13 +38,5 @@ module TTYtest
|
|
28
38
|
retry
|
29
39
|
end
|
30
40
|
end
|
31
|
-
|
32
|
-
TTYtest::Matchers::METHODS.each do |matcher_name|
|
33
|
-
define_method matcher_name do |*args|
|
34
|
-
synchronize do
|
35
|
-
capture.public_send(matcher_name, *args)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
41
|
end
|
40
42
|
end
|
data/lib/ttytest/tmux/session.rb
CHANGED
@@ -18,17 +18,19 @@ module TTYtest
|
|
18
18
|
|
19
19
|
def capture
|
20
20
|
contents = driver.tmux(*%W[capture-pane -t #{name} -p])
|
21
|
-
str = driver.tmux(*%W[display-message -t #{name} -p #\{cursor_x},#\{cursor_y},#\{cursor_flag}])
|
22
|
-
x, y, cursor_flag = str.split(',')
|
23
|
-
|
24
|
-
|
21
|
+
str = driver.tmux(*%W[display-message -t #{name} -p #\{cursor_x},#\{cursor_y},#\{cursor_flag},#\{pane_width},#\{pane_height}])
|
22
|
+
x, y, cursor_flag, width, height = str.split(',')
|
23
|
+
TTYtest::Capture.new(
|
24
|
+
contents.chomp("\n"),
|
25
|
+
cursor_x: x.to_i,
|
26
|
+
cursor_y: y.to_i,
|
27
|
+
width: width.to_i,
|
28
|
+
height: height.to_i,
|
29
|
+
cursor_visible: (cursor_flag != '0')
|
30
|
+
)
|
25
31
|
end
|
26
32
|
|
27
33
|
def send_keys(*keys)
|
28
|
-
driver.tmux(*%W[send-keys -t #{name}], *keys)
|
29
|
-
end
|
30
|
-
|
31
|
-
def send_raw(*keys)
|
32
34
|
driver.tmux(*%W[send-keys -t #{name} -l], *keys)
|
33
35
|
end
|
34
36
|
end
|
data/lib/ttytest/tmux/tmux.conf
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
set -g status off
|
data/lib/ttytest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ttytest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hawthorn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.6.8
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: TTYtest is an integration test framework for interactive tty applications
|