ttytest2 0.9.5 → 0.9.7

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: a1d11e60e54ba7d4b267d4b51d0fedeeade66563ac9957dd652b4fb94e57ed4b
4
- data.tar.gz: 568127f476a6fbed14d5288e4a07dddfa5512a9b050c9a31bd7071c92b7a90dc
3
+ metadata.gz: ad00f4819b188050fb5882adeac6578525082d1740c3b17a4320ec56b3f68b51
4
+ data.tar.gz: bf5dcc48c03fa7ab3cbf0c4e5780e479482f68fc19c149accd4e46c39d655cb2
5
5
  SHA512:
6
- metadata.gz: 78b47ae1254de6020012e16e1825f2d43d5fe5ef36eb8c7deb141023e6a33616561f8794a02b79113963aa290e2c7b30df8fc0e73c0d4adf1c59de093ed70973
7
- data.tar.gz: 2b9da01bb485487eb5e060a8a69ae9d7e989c5d5be1f873efe94a287773d0abc1106fd16002f88343c012d21a28642421ec0c8cbf222f886bcc32580abdd0154
6
+ metadata.gz: 8357acea4da5433d9131d72ab29c21a73c38f7c53140a0eff2a0ece7393eb47b2fb749b2539dee905bd4c3baa9f7aa2e502921a33a777b060cfe32568752933d
7
+ data.tar.gz: c4ecdc9782d7c1e0633dc5b3ff4579bcbac288e6cc4628a9e496ea91fe0777ab2e028896db6f398e1f2e9b66d050b2e9a04260da636dc2a1a2c7693640555ed0
data/README.md CHANGED
@@ -57,6 +57,13 @@ $
57
57
  TTY
58
58
  @tty.assert_cursor_position(x: 2, y: 2)
59
59
 
60
+ @tty.assert_contents_at(0, 0, '$ echo "Hello, world"')
61
+
62
+ @tty.assert_row_starts_with(0, '$ echo')
63
+ @tty.assert_row_ends_with(0, '"Hello, world"')
64
+ @tty.assert_row_starts_with(1, 'Hello')
65
+ @tty.assert_row_ends_with(1, ', world')
66
+
60
67
  @tty.print_rows # => ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ...]
61
68
 
62
69
  @tty.print # prints out the contents of the terminal
@@ -79,16 +86,15 @@ require 'ttytest'
79
86
 
80
87
  @tty.send_keys_one_at_a_time('ls')
81
88
  @tty.assert_row_ends_with(0, 'ls')
82
- @tty.send_keys(%(\n)) # make sure to use send_keys for 'multi-character' characters like \n, \r, \t, etc.
89
+ @tty.send_newline # builtins for common outputs line newline
83
90
 
84
91
  @tty.send_keys_one_at_a_time('ps')
85
92
  @tty.assert_row_ends_with(1, 'ps')
86
93
  @tty.send_keys(TTYtest:NEWLINE) # can use constants instead
87
94
 
88
-
89
95
  @tty.assert_row_starts_with(2, ENV['USER'])
90
96
  @tty.assert_row_ends_with(2, '$')
91
- @tty.send_newline # an alternative to the 2 above methods to send \n to the terminal
97
+ @tty.send_newline
92
98
 
93
99
  puts "\n#{@tty.capture}" # prints out the contents of the terminal, equivalent to @tty.print
94
100
  ```
@@ -108,6 +114,7 @@ Available assertions:
108
114
  * `assert_cursor_visible`
109
115
  * `assert_cursor_hidden`
110
116
  * `assert_contents(lines_of_terminal)`
117
+ * `assert_contents_at(row_start, row_end, expected_text)`
111
118
 
112
119
  ### Output
113
120
 
@@ -137,17 +144,20 @@ Helper functions to make sending output easier! They use the methods above under
137
144
  * `send_down_arrows(number_of_times)`
138
145
  * `send_home` # simulate pressing the Home key
139
146
  * `send_end` # simulate pressing the End key
147
+ * `send_clear` # clear the screen by sending clear ascii code
140
148
 
141
149
  ### Troubleshooting
142
150
 
143
151
  You can use the method rows to get all rows of the terminal as an array, of use the method capture to get the contents of the terminal window. This can be useful when troubleshooting.
144
152
 
145
153
  ``` ruby
146
- p @tty.rows # prints out the contents of the terminal as a array
147
- @tty.print_rows # equivalent to above
154
+ # you can use @tty.rows to access the entire pane, split by line into an array.
155
+ p @tty.rows # prints out the contents of the terminal as a array.
156
+ @tty.print_rows # equivalent to above, just for ease of use.
148
157
 
149
- puts "\n#{@tty.capture}" # prints out the contents of the terminal
150
- @tty.print # equivalent to above
158
+ # you can use @tty.capture to access the entire pane.
159
+ p "\n#{@tty.capture}" # prints out the contents of the terminal
160
+ @tty.print # equivalent to above, just for ease of use.
151
161
  ```
152
162
 
153
163
  ### Constants
@@ -51,10 +51,7 @@ module TTYtest
51
51
  def print
52
52
  puts "\n#{self}"
53
53
  end
54
-
55
- def print_rows
56
- puts rows
57
- end
54
+ alias print_rows print
58
55
 
59
56
  # @return [String] All rows of the captured terminal, separated by newlines
60
57
  def to_s
@@ -14,5 +14,5 @@ module TTYtest
14
14
  RIGHT_ARROW = "#{ESCAPE}[C".freeze
15
15
  LEFT_ARROW = "#{ESCAPE}[D".freeze
16
16
 
17
- CLEAR = 'clear'
17
+ CLEAR = "#{ESCAPE}[2J".freeze
18
18
  end
@@ -25,7 +25,7 @@ module TTYtest
25
25
  def assert_row_at(row_number, column_start, column_end, expected)
26
26
  expected = expected.rstrip
27
27
  actual = row(row_number)
28
- column_end += 1 if column_end.positive?
28
+ column_end += 1
29
29
  return if actual[column_start, column_end].eql?(expected)
30
30
 
31
31
  raise MatchError,
@@ -125,6 +125,33 @@ module TTYtest
125
125
  end
126
126
  alias assert_matches assert_contents
127
127
 
128
+ # Asserts the contents of the terminal at specified rows
129
+ # @param [String] expected the expected contents of the terminal at specified rows. Trailing whitespace on each line is ignored
130
+ # @raise [MatchError] if the terminal doesn't match the expected content
131
+ def assert_contents_at(row_start, row_end, expected)
132
+ expected_rows = expected.split("\n")
133
+ diff = []
134
+ matched = true
135
+ row_end += 1 if row_end.zero?
136
+
137
+ rows.slice(row_start, row_end).each_with_index do |actual_row, index|
138
+ expected_row = (expected_rows[index] || '').rstrip
139
+ if actual_row != expected_row
140
+ diff << "-#{expected_row}"
141
+ diff << "+#{actual_row}"
142
+ matched = false
143
+ else
144
+ diff << " #{actual_row}".rstrip
145
+ end
146
+ end
147
+
148
+ return if matched
149
+
150
+ raise MatchError,
151
+ "screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}"
152
+ end
153
+ alias assert_matches_at assert_contents_at
154
+
128
155
  METHODS = public_instance_methods
129
156
  end
130
157
  end
@@ -61,13 +61,15 @@ module TTYtest
61
61
  # @param [Integer] number of times to send up arrow
62
62
  # @!method send_keys_exact
63
63
  # Send tmux send-keys command to the terminal, such as DC or Enter, to simulate pressing that key in the terminal.
64
+ # @!method send_home
65
+ # Simulates typing in the Home key in the terminal.
66
+ # @!method send_end
67
+ # Simulates typing in the End key in the terminal.
68
+ # @!method send_clear
69
+ # Clears the screen in the terminal using ascii clear command.
64
70
  # @!method capture
65
71
  # Capture the current state of the terminal
66
72
  # @return [Capture] instantaneous state of the terminal when called
67
- # @!method print
68
- # Prints the current state of the terminal to stdout. See capture to get the raw string.
69
- # @!method print_rows
70
- # Prints the current state of the terminal as an array to stdout. See rows to get the raw array.
71
73
  def_delegators :@driver_terminal,
72
74
  :send_keys, :send_keys_one_at_a_time,
73
75
  :send_newline, :send_newlines,
@@ -75,9 +77,13 @@ module TTYtest
75
77
  :send_backspace, :send_backspaces,
76
78
  :send_left_arrow, :send_left_arrows, :send_right_arrow, :send_right_arrows,
77
79
  :send_down_arrow, :send_down_arrows, :send_up_arrow, :send_up_arrows,
78
- :send_keys_exact, :send_home, :send_end,
79
- :capture, :print, :print_rows
80
+ :send_keys_exact, :send_home, :send_end, :send_clear,
81
+ :capture
80
82
 
83
+ # @!method print
84
+ # Prints the current state of the terminal to stdout. See capture to get the raw string.
85
+ # @!method print_rows
86
+ # Prints the current state of the terminal as an array to stdout. See rows to get the raw array.
81
87
  # @!method rows
82
88
  # @return [Array<String>]
83
89
  # @see Capture#rows
@@ -102,7 +108,8 @@ module TTYtest
102
108
  # @!method cursor_hidden?
103
109
  # @see Capture#cursor_hidden?
104
110
  # @return [true,false]
105
- def_delegators :capture, :rows, :row,
111
+ def_delegators :capture, :print, :print_rows,
112
+ :rows, :row,
106
113
  :width, :height,
107
114
  :cursor_x, :cursor_y,
108
115
  :cursor_visible?, :cursor_hidden?
@@ -146,6 +146,11 @@ module TTYtest
146
146
  send_keys_exact(%(End))
147
147
  end
148
148
 
149
+ def send_clear
150
+ send_keys_one_at_a_time(TTYtest::CLEAR)
151
+ send_newline
152
+ end
153
+
149
154
  private
150
155
 
151
156
  attr_reader :driver, :name
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '0.9.5'
4
+ VERSION = '0.9.7'
5
5
  end
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  to push new version to github
2
- git tag v0.9.5
2
+ git tag v0.9.7
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.9.5.gem
7
+ gem push ttytest2-0.9.7.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.9.5
4
+ version: 0.9.7
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-29 00:00:00.000000000 Z
11
+ date: 2024-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler