ttytest2 0.8.4 → 0.8.6

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: 8801fe1b91cd7d371a9b1dc5668ad64b395e80778a6846c21ea004dd635b3107
4
- data.tar.gz: fe6847ef687fa1ece179ab5201173145f5ee1b243fa62f533ce5deddc290137a
3
+ metadata.gz: d5813f48d629bc3029c7c486652b5badcedbbac19b4c24946f50f8aa9df579c8
4
+ data.tar.gz: 86adb037b39d0da7cdcc9920d71f1655e8864e0171ae3fabfcb7301774908102
5
5
  SHA512:
6
- metadata.gz: 85b636e54bd9845b50b5d6cc5c9feaa3fac871ee4bf724409f191e38e86649fa695bb6a4917ea877b5d59d6d8dbb2fd0697aacff6122501fba14d6ae56f00654
7
- data.tar.gz: 38485e1cae3446068272b40a00d44eb12ce854442c87a8a0dbbd638d9b52a80a82b4c93a10e7f2c83312fef32aa88e771c7fe564d09d8db5e509907e68015bee
6
+ metadata.gz: e6fe94d8ef4c818a94b487f01efee8ab8d2c1ed828b30679eed643e4388c9e77178d00c25e761881098b47512a51f696c597a82fabfa68d9e6a569ea52b0e15e
7
+ data.tar.gz: 0ce32ed7e12445f1c9d4fee55ec2f9b5c27a3890c73a1a3a52b45c39c5c1931ebc08bcc6f04bf5e55d372a03b82e4b19a2ccfee4a487a427d52047d92f3fec84
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,15 +1,14 @@
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
13
  UP_ARROW = "#{ESCAPE}[A".freeze
15
14
  DOWN_ARROW = "#{ESCAPE}[B".freeze
@@ -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.6'
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.6
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.6.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.6
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