ttytest2 0.8.5 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b98c6cd8789c970147b325d01c3af8e4b4eef8f32bac57aae4036b8ce3586d9
4
- data.tar.gz: ddbfe244faedd701d96bc98ce103b49a8d825517e0664dbbea858954319290b4
3
+ metadata.gz: 9c871fc585971f615966d7797478185dd942e78b6cfcfc9324773edfd789664f
4
+ data.tar.gz: 4a7a6b509c222510918cdad040e958c09bdd653700b3a3871f087cdadf7a5c9b
5
5
  SHA512:
6
- metadata.gz: f4862a535e862eb7fa58bc3373306ee3f82b939f5652b9b334e55acb5437358159cef2dd02d551823ff47e62625ac3b69200c526365fee2277882a617156acbd
7
- data.tar.gz: 7ceed490dc0fb92b77ace530650a92691fdc69fa1833344b8e0000d5b1f21fe654d995b63825b5512d289c75079a83abc117d0e24c85483fda7efc5bf634bda2
6
+ metadata.gz: 84d1c8b052ce38fdad9d0780774a0aae6a378b60804a156a74099e69b62f741f49b00887296e03a49030fe62c25d8bceef2b28e3a3ad2ddbd979cabbf7643b28
7
+ data.tar.gz: 4fc3e3186fe6827bb987f18e2d04aa9cfbe49c6c31f3d8a5e8ab92c6ec6f81264df11298cddbdeb70c46630f20ba056d29608f2df90549d6e3cbd25dbe7f4d29
data/README.md CHANGED
@@ -20,14 +20,15 @@ It works by running commands inside a tmux session, capturing the pane, and comp
20
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
21
 
22
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)`
23
+ * specify row matches expected text exactly: `assert_row(row_number, expected_text) `
24
+ * specify expected position of expected text: `assert_row_at(row_number, column_start_position, column_end_position, expected_text)`
25
+ * specify row contains expected text: `assert_row_like(row_number, expected_text)`
26
+ * specify row starts with expected text: `assert_row_starts_with(row_number, expected_text)`
27
+ * specify row ends with expected text: `assert_row_ends_with(row_number, expected_text)`
28
+ * specify the current cursor position matches expected: `assert_cursor_position(x: x, y: y)`
29
+ * specify the cursor is currently visible: `assert_cursor_visible`
30
+ * specify the cursor is currently hidden: `assert_cursor_hidden`
31
+ * specify the contents of the entire terminal window: `assert_contents(lines_of_terminal)`
31
32
 
32
33
  ### Sending output
33
34
 
@@ -80,6 +81,10 @@ require 'ttytest'
80
81
  @tty.send_keys_one_at_a_time('ps')
81
82
  @tty.assert_row_ends_with(0, 'ps')
82
83
  @tty.send_keys(TTYtest:NEWLINE) # can use constants instead
84
+
85
+ @tty.assert_row_starts_with(0, ENV['USER'])
86
+ @tty.assert_row_ends_with(0, '$')
87
+ @tty.send_newline # an alternative to the 2 above methods to send \n to the terminal
83
88
  ```
84
89
 
85
90
  ### Constants
@@ -88,7 +93,6 @@ There are some commonly used keys available as constants to make interacting wit
88
93
 
89
94
  ``` ruby
90
95
  TTYtest::BACKSPACE
91
- TTYtest::DELETE
92
96
  TTYtest::TAB
93
97
  TTYtest::CTRLF
94
98
  TTYtest::CTRLC
@@ -3,17 +3,16 @@
3
3
  # some constants that can be used with send_keys, just to help out people creating tests
4
4
  module TTYtest
5
5
  BACKSPACE = 127.chr
6
- DELETE = '^[[3~'
7
6
  TAB = 9.chr
8
7
  CTRLF = 6.chr
9
8
  CTRLC = 3.chr
10
9
  CTRLD = '\004'
11
10
  ESCAPE = 27.chr
12
11
 
13
- UP_ARROW = '^[[A'
14
- DOWN_ARROW = '^[[B'
15
- RIGHT_ARROW = '^[[C'
16
- LEFT_ARROW = '^[[D'
12
+ UP_ARROW = "#{ESCAPE}[A".freeze
13
+ DOWN_ARROW = "#{ESCAPE}[B".freeze
14
+ RIGHT_ARROW = "#{ESCAPE}[C".freeze
15
+ LEFT_ARROW = "#{ESCAPE}[D".freeze
17
16
 
18
17
  CLEAR = 'clear'
19
18
  end
@@ -3,10 +3,10 @@
3
3
  module TTYtest
4
4
  # Assertions for ttytest2.
5
5
  module Matchers
6
- # Asserts the contents of a single row
6
+ # Asserts the contents of a single row match the value expected
7
7
  # @param [Integer] row_number the row (starting from 0) to test against
8
8
  # @param [String] expected the expected value of the row. Any trailing whitespace is ignored
9
- # @raise [MatchError] if the row doesn't match
9
+ # @raise [MatchError] if the row doesn't match exactly
10
10
  def assert_row(row_number, expected)
11
11
  expected = expected.rstrip
12
12
  actual = row(row_number)
@@ -16,7 +16,25 @@ module TTYtest
16
16
  "expected row #{row_number} to be #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}"
17
17
  end
18
18
 
19
- # Asserts the contents of a single row contains expected
19
+ # Asserts the contents of a single row contains the expected string at a specific position
20
+ # @param [Integer] row_number the row (starting from 0) to test against
21
+ # @param [Integer] column_start the column position to start comparing expected against
22
+ # @param [Integer] columns_end the column position to end comparing expected against
23
+ # @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
24
+ # @raise [MatchError] if the row doesn't match
25
+ def assert_row_at(row_number, column_start, column_end, expected)
26
+ expected = expected.rstrip
27
+ actual = row(row_number)
28
+ column_end += 1 if column_end.positive?
29
+ return if actual[column_start, column_end].eql?(expected)
30
+
31
+ raise MatchError,
32
+ "expected row #{row_number} to contain #{expected[column_start,
33
+ column_end]} at #{column_start}-#{column_end} and got #{actual[column_start,
34
+ column_end]}\nEntire screen:\n#{self}"
35
+ end
36
+
37
+ # Asserts the contents of a single row contains the value expected
20
38
  # @param [Integer] row_number the row (starting from 0) to test against
21
39
  # @param [String] expected the expected value contained in the row. Any trailing whitespace is ignored
22
40
  # @raise [MatchError] if the row doesn't match
@@ -29,7 +47,7 @@ module TTYtest
29
47
  "expected row #{row_number} to be like #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}"
30
48
  end
31
49
 
32
- # Asserts the contents of a single row start with expected
50
+ # Asserts the contents of a single row starts with expected string
33
51
  # @param [Integer] row_number the row (starting from 0) to test against
34
52
  # @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
35
53
  # @raise [MatchError] if the row doesn't match
@@ -21,13 +21,23 @@ module TTYtest
21
21
  # @!method send_keys(*keys)
22
22
  # Simulate typing keys into the terminal. For canonical cli's/shells which read line by line.
23
23
  # @param [String] keys keys to send to the terminal
24
- # @!method send_keys_one_at_a_time(*keys)
24
+ # @!method send_keys_one_at_a_time(keys)
25
25
  # Simulate typing keys into the terminal. For noncanonical cli's/shells which read character by character.
26
26
  # @param [String] keys keys to send to the terminal
27
+ # @!method send_newline
28
+ # Simulate typing enter by sending newline character to the terminal.
29
+ # @!method send_delete
30
+ # Simulate typing the delete key in the terminal.
31
+ # @!method send_backspace
32
+ # Simulate typing the backspace key in the terminal.
33
+ # @!method send_keys_exact
34
+ # Send tmux send-keys command to the terminal, such as DC or Enter, to simulate pressing that key in the terminal.
27
35
  # @!method capture
28
36
  # Capture the current state of the terminal
29
37
  # @return [Capture] instantaneous state of the terminal when called
30
- def_delegators :@driver_terminal, :send_keys, :send_keys_one_at_a_time, :send_newline, :capture
38
+ def_delegators :@driver_terminal,
39
+ :send_keys, :send_keys_one_at_a_time, :send_newline, :send_delete, :send_backspace, :send_keys_exact,
40
+ :capture
31
41
 
32
42
  # @!method rows
33
43
  # @return [Array<String>]
@@ -38,10 +38,15 @@ module TTYtest
38
38
  )
39
39
  end
40
40
 
41
+ # Send the array of keys as a string literal to tmux.
42
+ # Will not be interpreted as send-keys values like Enter, Escape, DC for Delete, etc.
43
+ # @param [%w()] keys the keys to send to tmux
41
44
  def send_keys(*keys)
42
45
  driver.tmux(*%W[send-keys -t #{name} -l], *keys)
43
46
  end
44
47
 
48
+ # Send a string of keys one character at a time as literals to tmux.
49
+ # @param [String] keys the keys to send one at a time to tmux
45
50
  def send_keys_one_at_a_time(keys)
46
51
  keys.split('').each do |key|
47
52
  driver.tmux(*%W[send-keys -t #{name} -l], key)
@@ -52,6 +57,22 @@ module TTYtest
52
57
  driver.tmux(*%W[send-keys -t #{name} -l], %(\n))
53
58
  end
54
59
 
60
+ def send_delete
61
+ send_keys_exact(%(DC))
62
+ end
63
+
64
+ def send_backspace
65
+ send_keys_exact(%(BSpace))
66
+ end
67
+
68
+ # Useful to send send-keys commands to tmux without sending them as a string literal.
69
+ # So you can send Escape for escape key, DC for delete, etc.
70
+ # Uses the same key bindings as bind-key as well. C-c represents Ctrl + C keys, F1 is F1 key, etc.
71
+ # @param [String] keys the keys to send to tmux
72
+ def send_keys_exact(keys)
73
+ driver.tmux(*%W[send-keys -t #{name}], keys)
74
+ end
75
+
55
76
  private
56
77
 
57
78
  attr_reader :driver, :name
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '0.8.5'
4
+ VERSION = '0.9.0'
5
5
  end
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  to push new version to github,
2
- git tag v0.8.5
2
+ git tag v0.9.0
3
3
  git push origin --tags
4
4
 
5
5
  to push new version to rubygems.org
6
6
  gem build ttytest2.gemspec
7
- gem push ttytest2-0.8.5.gem
7
+ gem push ttytest2-0.9.0.gem
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.5
4
+ version: 0.9.0
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-15 00:00:00.000000000 Z
11
+ date: 2024-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler