ttytest2 0.7.1 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/ttytest/capture.rb +2 -0
- data/lib/ttytest/matchers.rb +33 -4
- data/lib/ttytest/terminal.rb +2 -0
- data/lib/ttytest/tmux/session.rb +5 -4
- data/lib/ttytest/version.rb +3 -1
- data/lib/ttytest.rb +3 -0
- data/notes.txt +2 -2
- 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: 7a35421907aa8999c90ba5e18959aa659bf6a9b14248ae46acddb7d18f1db0f5
|
4
|
+
data.tar.gz: bbf9762f20e681e29861f9f04090afa03c238fccee3ea6e3d2e8314fb6fa88c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 978ca3331442680de64cd74fdd9e7167526c4a521dc9ed41fdbd8e08d89d9caebb617d6427edb58b5bc79b1b0a522cbb4a54d0854a5f8a3953f22777adebc0d9
|
7
|
+
data.tar.gz: 4115b6301cba03d98b92a6b40f9264b3a0630f28421fae34d402bbfef941f6704895e6b73fee83ddde511b2523f602a16d351434366392a75a1e61457164432d
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ 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/
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/ttytest2.svg)](https://rubygems.org/gems/ttytest2)
|
10
10
|
|
11
11
|
## Minimum Requirements
|
12
12
|
|
@@ -18,6 +18,8 @@ It works by running commands inside a tmux session, capturing the pane, and comp
|
|
18
18
|
### Example
|
19
19
|
|
20
20
|
``` ruby
|
21
|
+
require 'ttytest'
|
22
|
+
|
21
23
|
@tty = TTYtest.new_terminal(%{PS1='$ ' /bin/sh}, width: 80, height: 24)
|
22
24
|
@tty.assert_row(0, '$')
|
23
25
|
@tty.assert_cursor_position(x: 2, y: 0)
|
@@ -41,6 +43,8 @@ The main way to use TTYtest is through assertions. When called on a `TTYtest::Te
|
|
41
43
|
Available assertions:
|
42
44
|
* `assert_row(row_number, expected_text)`
|
43
45
|
* `assert_row_like(row_number, expected_text)`
|
46
|
+
* `assert_row_starts_with(row_number, expected_text)`
|
47
|
+
* `assert_row_ends_with(row_number, expected_text)`
|
44
48
|
* `assert_cursor_position(x: x, y: y)`
|
45
49
|
* `assert_cursor_visible`
|
46
50
|
* `assert_cursor_hidden`
|
data/lib/ttytest/capture.rb
CHANGED
data/lib/ttytest/matchers.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TTYtest
|
4
|
+
# Assertions for ttytest2.
|
2
5
|
module Matchers
|
3
6
|
# Asserts the contents of a single row
|
4
7
|
# @param [Integer] row_number the row (starting from 0) to test against
|
@@ -7,15 +10,15 @@ module TTYtest
|
|
7
10
|
def assert_row(row_number, expected)
|
8
11
|
expected = expected.rstrip
|
9
12
|
actual = row(row_number)
|
10
|
-
return
|
13
|
+
return if actual == expected
|
11
14
|
|
12
15
|
raise MatchError,
|
13
16
|
"expected row #{row_number} to be #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}"
|
14
17
|
end
|
15
18
|
|
16
|
-
# Asserts the contents of a single row
|
19
|
+
# Asserts the contents of a single row contains expected
|
17
20
|
# @param [Integer] row_number the row (starting from 0) to test against
|
18
|
-
# @param [String] expected the expected value
|
21
|
+
# @param [String] expected the expected value contained in the row. Any trailing whitespace is ignored
|
19
22
|
# @raise [MatchError] if the row doesn't match
|
20
23
|
def assert_row_like(row_number, expected)
|
21
24
|
expected = expected.rstrip
|
@@ -26,6 +29,32 @@ module TTYtest
|
|
26
29
|
"expected row #{row_number} to be like #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}"
|
27
30
|
end
|
28
31
|
|
32
|
+
# Asserts the contents of a single row start with expected
|
33
|
+
# @param [Integer] row_number the row (starting from 0) to test against
|
34
|
+
# @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
|
35
|
+
# @raise [MatchError] if the row doesn't match
|
36
|
+
def assert_row_starts_with(row_number, expected)
|
37
|
+
expected = expected.rstrip
|
38
|
+
actual = row(row_number)
|
39
|
+
return if actual.start_with?(expected)
|
40
|
+
|
41
|
+
raise MatchError,
|
42
|
+
"expected row #{row_number} to start with #{expected.inspect} and got #{actual.inspect}\nEntire screen:\n#{self}"
|
43
|
+
end
|
44
|
+
|
45
|
+
# Asserts the contents of a single row end with expected
|
46
|
+
# @param [Integer] row_number the row (starting from 0) to test against
|
47
|
+
# @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
|
48
|
+
# @raise [MatchError] if the row doesn't match
|
49
|
+
def assert_row_ends_with(row_number, expected)
|
50
|
+
expected = expected.rstrip
|
51
|
+
actual = row(row_number)
|
52
|
+
return if actual.end_with?(expected)
|
53
|
+
|
54
|
+
raise MatchError,
|
55
|
+
"expected row #{row_number} to end with #{expected.inspect} and got #{actual.inspect}\nEntire screen:\n#{self}"
|
56
|
+
end
|
57
|
+
|
29
58
|
# Asserts that the cursor is in the expected position
|
30
59
|
# @param [Integer] x cursor x (row) position, starting from 0
|
31
60
|
# @param [Integer] y cursor y (column) position, starting from 0
|
@@ -33,7 +62,7 @@ module TTYtest
|
|
33
62
|
def assert_cursor_position(x, y)
|
34
63
|
expected = [x, y]
|
35
64
|
actual = [cursor_x, cursor_y]
|
36
|
-
return
|
65
|
+
return if actual == expected
|
37
66
|
|
38
67
|
raise MatchError,
|
39
68
|
"expected cursor to be at #{expected.inspect} but was at #{actual.inspect}\nEntire screen:\n#{self}"
|
data/lib/ttytest/terminal.rb
CHANGED
data/lib/ttytest/tmux/session.rb
CHANGED
@@ -2,19 +2,20 @@
|
|
2
2
|
|
3
3
|
module TTYtest
|
4
4
|
module Tmux
|
5
|
+
# tmux session manager
|
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])
|
data/lib/ttytest/version.rb
CHANGED
data/lib/ttytest.rb
CHANGED
data/notes.txt
CHANGED