ttytest2 0.8.4 → 0.8.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8801fe1b91cd7d371a9b1dc5668ad64b395e80778a6846c21ea004dd635b3107
4
- data.tar.gz: fe6847ef687fa1ece179ab5201173145f5ee1b243fa62f533ce5deddc290137a
3
+ metadata.gz: 3b98c6cd8789c970147b325d01c3af8e4b4eef8f32bac57aae4036b8ce3586d9
4
+ data.tar.gz: ddbfe244faedd701d96bc98ce103b49a8d825517e0664dbbea858954319290b4
5
5
  SHA512:
6
- metadata.gz: 85b636e54bd9845b50b5d6cc5c9feaa3fac871ee4bf724409f191e38e86649fa695bb6a4917ea877b5d59d6d8dbb2fd0697aacff6122501fba14d6ae56f00654
7
- data.tar.gz: 38485e1cae3446068272b40a00d44eb12ce854442c87a8a0dbbd638d9b52a80a82b4c93a10e7f2c83312fef32aa88e771c7fe564d09d8db5e509907e68015bee
6
+ metadata.gz: f4862a535e862eb7fa58bc3373306ee3f82b939f5652b9b334e55acb5437358159cef2dd02d551823ff47e62625ac3b69200c526365fee2277882a617156acbd
7
+ data.tar.gz: 7ceed490dc0fb92b77ace530650a92691fdc69fa1833344b8e0000d5b1f21fe654d995b63825b5512d289c75079a83abc117d0e24c85483fda7efc5bf634bda2
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # ttytest2
2
2
 
3
- TTYtest2 is an acceptance test framework for interactive console applications. It's like [capybara](https://github.com/teamcapybara/capybara) for the terminal.
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
- Forked from https://github.com/jhawthorn/ttytest, because I had some features I needed for my own project.
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
 
@@ -29,8 +29,16 @@ Available assertions:
29
29
  * `assert_cursor_hidden`
30
30
  * `assert_contents(lines_of_terminal)`
31
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)`
32
39
 
33
40
  ### Example Canonical CLI/Shell
41
+
34
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.
35
43
 
36
44
  ``` ruby
@@ -53,7 +61,10 @@ p @tty.rows # => ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ..
53
61
  ```
54
62
 
55
63
  ### Example Noncanonical CLI/Shell
56
- 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.
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 />
57
68
 
58
69
  ``` ruby
59
70
  require 'ttytest'
@@ -65,6 +76,31 @@ require 'ttytest'
65
76
  @tty.send_keys_one_at_a_time('ls')
66
77
  @tty.assert_row_ends_with(0, 'ls')
67
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
83
+ ```
84
+
85
+ ### Constants
86
+
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.
88
+
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
68
104
  ```
69
105
 
70
106
  ## Docker
@@ -1,20 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # some constants that can be used with send_keys, just to help out people creating tests
4
- # may not work with all terminal emulators
5
4
  module TTYtest
6
5
  BACKSPACE = 127.chr
6
+ DELETE = '^[[3~'
7
7
  TAB = 9.chr
8
8
  CTRLF = 6.chr
9
9
  CTRLC = 3.chr
10
10
  CTRLD = '\004'
11
11
  ESCAPE = 27.chr
12
- NEWLINE = '\n'
13
12
 
14
- UP_ARROW = "#{ESCAPE}[A".freeze
15
- DOWN_ARROW = "#{ESCAPE}[B".freeze
16
- RIGHT_ARROW = "#{ESCAPE}[C".freeze
17
- LEFT_ARROW = "#{ESCAPE}[D".freeze
13
+ UP_ARROW = '^[[A'
14
+ DOWN_ARROW = '^[[B'
15
+ RIGHT_ARROW = '^[[C'
16
+ LEFT_ARROW = '^[[D'
18
17
 
19
18
  CLEAR = 'clear'
20
19
  end
@@ -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>]
@@ -48,6 +48,10 @@ module TTYtest
48
48
  end
49
49
  end
50
50
 
51
+ def send_newline
52
+ driver.tmux(*%W[send-keys -t #{name} -l], %(\n))
53
+ end
54
+
51
55
  private
52
56
 
53
57
  attr_reader :driver, :name
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '0.8.4'
4
+ VERSION = '0.8.5'
5
5
  end
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  to push new version to github,
2
- git tag v0.8.4
2
+ git tag v0.8.5
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.4.gem
7
+ gem push ttytest2-0.8.5.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.4
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-14 00:00:00.000000000 Z
11
+ date: 2024-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler