ttytest2 1.0.5 → 1.0.7
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 +4 -4
- data/README.md +3 -2
- data/lib/ttytest/{matchers.rb → assertions.rb} +115 -46
- data/lib/ttytest/capture.rb +1 -1
- data/lib/ttytest/terminal.rb +2 -2
- data/lib/ttytest/version.rb +1 -1
- data/lib/ttytest.rb +16 -1
- data/notes.txt +2 -2
- data/todo.txt +0 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ec86d17bfe3b3a9c9485f0b53c14f4dcfebd5e875dd2ba1de7f26c7ef4b1a87
|
4
|
+
data.tar.gz: 2b53db154e9c680b89897bc46cffe087d415ce22049727ec1b3ff698ce80aba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5db41e82f2c81e5df9e8305f51431b58fafac9abe95b23eaf64f7e7f8e13c64ca5b1be21784b67438938579dd503cbd430128c6984e94b8fa69990c9d9e7b0cf
|
7
|
+
data.tar.gz: 22e3f4c4609432321cf5c7abe0f061e15f52816f89f1d8dd87283aef6d9d78dd661fe991edc074dbfd354024aaa59278799d332b29d3cd32460ef0d2bf665d4d
|
data/README.md
CHANGED
@@ -262,10 +262,11 @@ Max wait time represents the amount of time in seconds that ttytest2 will keep r
|
|
262
262
|
You can configure max wait time as shown below.
|
263
263
|
|
264
264
|
``` ruby
|
265
|
-
@tty = TTYtest::new_terminal('')
|
266
|
-
@tty.max_wait_time = 1 # sets the max wait time to 1 second
|
265
|
+
@tty = TTYtest::new_terminal('', max_wait_time: 1) # sets the max wait time to 1 second
|
267
266
|
|
268
267
|
@tty.assert_row(0, 'echo Hello, world') # this assertion would fail after 1 second
|
268
|
+
@tty.max_wait_time = 3
|
269
|
+
@tty.assert_row(0, 'echo Hello, world') # this assertion would fail after 3 seconds
|
269
270
|
```
|
270
271
|
|
271
272
|
## Troubleshooting
|
@@ -2,32 +2,7 @@
|
|
2
2
|
|
3
3
|
module TTYtest
|
4
4
|
# Assertions for ttytest2.
|
5
|
-
module
|
6
|
-
def get_inspection(actual)
|
7
|
-
if actual.nil?
|
8
|
-
'nil'
|
9
|
-
else
|
10
|
-
actual.inspect
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def get_inspection_bounded(actual, column_start, column_end)
|
15
|
-
if actual.nil?
|
16
|
-
'nil'
|
17
|
-
else
|
18
|
-
actual[column_start, column_end]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def validate(row)
|
23
|
-
return if @height.nil?
|
24
|
-
return unless row >= @height
|
25
|
-
|
26
|
-
raise MatchError,
|
27
|
-
"row is at #{row}, which is greater than set height #{height}, so assertions will fail. If intentional, set height larger or break apart tests.\n
|
28
|
-
Entire screen:\n#{self}"
|
29
|
-
end
|
30
|
-
|
5
|
+
module Assertions
|
31
6
|
# Asserts the contents of a single row match the value expected
|
32
7
|
# @param [Integer] row_number the row (starting from 0) to test against
|
33
8
|
# @param [String] expected the expected value of the row. Any trailing whitespace is ignored
|
@@ -113,6 +88,7 @@ module TTYtest
|
|
113
88
|
raise MatchError,
|
114
89
|
"expected row #{row_number} to start with #{expected.inspect} and got #{get_inspection(actual)}\nEntire screen:\n#{self}"
|
115
90
|
end
|
91
|
+
alias assert_line_starts_with assert_row_starts_with
|
116
92
|
|
117
93
|
# Asserts the contents of a single row end with expected
|
118
94
|
# @param [Integer] row_number the row (starting from 0) to test against
|
@@ -128,6 +104,7 @@ module TTYtest
|
|
128
104
|
raise MatchError,
|
129
105
|
"expected row #{row_number} to end with #{expected.inspect} and got #{get_inspection(actual)}\nEntire screen:\n#{self}"
|
130
106
|
end
|
107
|
+
alias assert_line_ends_with assert_row_ends_with
|
131
108
|
|
132
109
|
# Asserts the contents of a single row match against the passed in regular expression
|
133
110
|
# @param [Integer] row_number the row (starting from 0) to test against
|
@@ -143,6 +120,7 @@ module TTYtest
|
|
143
120
|
raise MatchError,
|
144
121
|
"expected row #{row_number} to match regexp #{regexp_str} but it did not. Row value #{get_inspection(actual)}\nEntire screen:\n#{self}"
|
145
122
|
end
|
123
|
+
alias assert_line_regexp assert_row_regexp
|
146
124
|
|
147
125
|
# Asserts the contents of a multiple rows each match against the passed in regular expression
|
148
126
|
# @param [Integer] row_start the row (starting from 0) to test against
|
@@ -161,6 +139,7 @@ module TTYtest
|
|
161
139
|
"expected row #{index} to match regexp #{regexp_str} but it did not. Row value #{get_inspection(actual_row)}\nEntire screen:\n#{self}"
|
162
140
|
end
|
163
141
|
end
|
142
|
+
alias assert_line_each_match_regexp assert_rows_each_match_regexp
|
164
143
|
|
165
144
|
# Asserts that the cursor is in the expected position
|
166
145
|
# @param [Integer] x cursor x (row) position, starting from 0
|
@@ -190,29 +169,11 @@ module TTYtest
|
|
190
169
|
raise MatchError, "expected cursor to be hidden was visible\nEntire screen:\n#{self}"
|
191
170
|
end
|
192
171
|
|
193
|
-
def matched(expected, actual)
|
194
|
-
expected_rows = expected.split("\n")
|
195
|
-
diff = []
|
196
|
-
matched = true
|
197
|
-
actual.each_with_index do |actual_row, index|
|
198
|
-
expected_row = (expected_rows[index] || '').rstrip
|
199
|
-
if actual_row != expected_row
|
200
|
-
diff << "-#{expected_row}"
|
201
|
-
diff << "+#{actual_row}"
|
202
|
-
matched = false
|
203
|
-
else
|
204
|
-
diff << " #{actual_row}".rstrip
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
[matched, diff]
|
209
|
-
end
|
210
|
-
|
211
172
|
# Asserts the full contents of the terminal
|
212
173
|
# @param [String] expected the full expected contents of the terminal. Trailing whitespace on each line is ignored
|
213
174
|
# @raise [MatchError] if the terminal doesn't match the expected content
|
214
175
|
def assert_contents(expected)
|
215
|
-
matched, diff =
|
176
|
+
matched, diff = get_diff(expected, rows)
|
216
177
|
|
217
178
|
return if matched
|
218
179
|
|
@@ -229,7 +190,7 @@ module TTYtest
|
|
229
190
|
validate(row_end)
|
230
191
|
row_end += 1 if row_end.zero?
|
231
192
|
|
232
|
-
matched, diff =
|
193
|
+
matched, diff = get_diff(expected, rows.slice(row_start, row_end))
|
233
194
|
|
234
195
|
return if matched
|
235
196
|
|
@@ -239,6 +200,114 @@ module TTYtest
|
|
239
200
|
alias assert_matches_at assert_contents_at
|
240
201
|
alias assert_rows assert_contents_at
|
241
202
|
|
203
|
+
def assert_file_exists(file_path)
|
204
|
+
raise file_not_found_error(file_path) unless File.exist?(file_path)
|
205
|
+
raise file_is_dir_error(file_path) unless File.file?(file_path)
|
206
|
+
end
|
207
|
+
|
208
|
+
def assert_file_doesnt_exist(file_path)
|
209
|
+
return unless File.exist?(file_path) || File.file?(file_path)
|
210
|
+
|
211
|
+
raise MatchError,
|
212
|
+
"File with path #{file_path} was found or is a directory when it was asserted it did not exist.\nEntire screen:\n#{self}"
|
213
|
+
end
|
214
|
+
|
215
|
+
def assert_file_contains(file_path, needle)
|
216
|
+
raise file_not_found_error(file_path) unless File.exist?(file_path)
|
217
|
+
raise file_is_dir_error(file_path) unless File.file?(file_path)
|
218
|
+
|
219
|
+
file_contains = false
|
220
|
+
File.foreach(file_path) do |line|
|
221
|
+
if line.include?(needle)
|
222
|
+
file_contains = true
|
223
|
+
break
|
224
|
+
end
|
225
|
+
end
|
226
|
+
return if file_contains
|
227
|
+
|
228
|
+
raise MatchError,
|
229
|
+
"File with path #{file_path} did not contain #{needle}.\nEntire screen:\n#{self}"
|
230
|
+
end
|
231
|
+
alias assert_file_like assert_file_contains
|
232
|
+
|
233
|
+
def assert_file_has_permissions(file_path, permissions)
|
234
|
+
raise file_not_found_error(file_path) unless File.exist?(file_path)
|
235
|
+
raise file_is_dir_error(file_path) unless File.file?(file_path)
|
236
|
+
|
237
|
+
file_mode = File.stat(file_path).mode
|
238
|
+
perms_octal = format('%o', file_mode)[-3...]
|
239
|
+
return if perms_octal == permissions
|
240
|
+
|
241
|
+
raise MatchError,
|
242
|
+
"File had permissions #{perms_octal}, not #{permissions} as expected.\n Entire screen:\n#{self}"
|
243
|
+
end
|
244
|
+
|
245
|
+
def assert_file_has_line_count(file_path, expected_count)
|
246
|
+
raise file_not_found_error(file_path) unless File.exist?(file_path)
|
247
|
+
raise file_is_dir_error(file_path) unless File.file?(file_path)
|
248
|
+
|
249
|
+
actual_count = File.foreach(file_path).count
|
250
|
+
return if actual_count == expected_count
|
251
|
+
|
252
|
+
raise MatchError,
|
253
|
+
"File had #{actual_count} lines, not #{expected_count} lines as expected.\nEntire screen:\n#{self}"
|
254
|
+
end
|
255
|
+
|
242
256
|
METHODS = public_instance_methods
|
257
|
+
|
258
|
+
private
|
259
|
+
|
260
|
+
def get_inspection(actual)
|
261
|
+
if actual.nil?
|
262
|
+
'nil'
|
263
|
+
else
|
264
|
+
actual.inspect
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def get_inspection_bounded(actual, column_start, column_end)
|
269
|
+
if actual.nil?
|
270
|
+
'nil'
|
271
|
+
else
|
272
|
+
actual[column_start, column_end]
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
def validate(row)
|
277
|
+
return if @height.nil?
|
278
|
+
return unless row >= @height
|
279
|
+
|
280
|
+
raise MatchError,
|
281
|
+
"row is at #{row}, which is greater than set height #{height}, so assertions will fail. If intentional, set height larger or break apart tests.\n
|
282
|
+
Entire screen:\n#{self}"
|
283
|
+
end
|
284
|
+
|
285
|
+
def get_diff(expected, actual)
|
286
|
+
expected_rows = expected.split("\n")
|
287
|
+
diff = []
|
288
|
+
matched = true
|
289
|
+
actual.each_with_index do |actual_row, index|
|
290
|
+
expected_row = (expected_rows[index] || '').rstrip
|
291
|
+
if actual_row != expected_row
|
292
|
+
diff << "-#{expected_row}"
|
293
|
+
diff << "+#{actual_row}"
|
294
|
+
matched = false
|
295
|
+
else
|
296
|
+
diff << " #{actual_row}".rstrip
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
[matched, diff]
|
301
|
+
end
|
302
|
+
|
303
|
+
def file_not_found_error(file_path)
|
304
|
+
raise MatchError,
|
305
|
+
"File with path #{file_path} was not found when asserted it did exist.\nEntire screen:\n#{self}"
|
306
|
+
end
|
307
|
+
|
308
|
+
def file_is_dir_error(file_path)
|
309
|
+
raise MatchError,
|
310
|
+
"File with path #{file_path} is a directory.\nEntire screen:\n#{self}"
|
311
|
+
end
|
243
312
|
end
|
244
313
|
end
|
data/lib/ttytest/capture.rb
CHANGED
@@ -7,7 +7,7 @@ module TTYtest
|
|
7
7
|
# @attr_reader [Integer] cursor_x The cursor's column (starting at 0) in the captured terminal.
|
8
8
|
# @attr_reader [Integer] cursor_y The cursor's row (starting at 0) in the captured terminal.
|
9
9
|
class Capture
|
10
|
-
include TTYtest::
|
10
|
+
include TTYtest::Assertions
|
11
11
|
|
12
12
|
attr_reader :cursor_x, :cursor_y, :width, :height
|
13
13
|
|
data/lib/ttytest/terminal.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'forwardable'
|
4
|
-
require 'ttytest/
|
4
|
+
require 'ttytest/assertions'
|
5
5
|
require 'ttytest/capture'
|
6
6
|
|
7
7
|
module TTYtest
|
@@ -193,7 +193,7 @@ module TTYtest
|
|
193
193
|
:cursor_x, :cursor_y,
|
194
194
|
:cursor_visible?, :cursor_hidden?
|
195
195
|
|
196
|
-
|
196
|
+
Assertions::METHODS.each do |matcher_name|
|
197
197
|
define_method matcher_name do |*args, **kwargs|
|
198
198
|
synchronize do
|
199
199
|
capture.public_send(matcher_name, *args, **kwargs)
|
data/lib/ttytest/version.rb
CHANGED
data/lib/ttytest.rb
CHANGED
@@ -25,7 +25,22 @@ module TTYtest
|
|
25
25
|
# @!method new_sh_terminal(width: 80, height: 24)
|
26
26
|
# Create a new terminal using '/bin/sh' with ability to set width and height.
|
27
27
|
# Useful for Unixes.
|
28
|
-
def_delegators :driver
|
28
|
+
def_delegators :driver
|
29
|
+
|
30
|
+
def new_terminal(cmd, width: 80, height: 24, max_wait_time: 2)
|
31
|
+
@max_wait_time = max_wait_time
|
32
|
+
driver.new_terminal(cmd, width: width, height: height)
|
33
|
+
end
|
34
|
+
|
35
|
+
def new_default_sh_terminal(max_wait_time: 2)
|
36
|
+
@max_wait_time = max_wait_time
|
37
|
+
driver.new_default_sh_terminal
|
38
|
+
end
|
39
|
+
|
40
|
+
def new_sh_terminal(width: 80, height: 24, max_wait_time: 2)
|
41
|
+
@max_wait_time = max_wait_time
|
42
|
+
driver.new_sh_terminal(width: width, height: height)
|
43
|
+
end
|
29
44
|
end
|
30
45
|
|
31
46
|
# The error type raised when an assertion fails.
|
data/notes.txt
CHANGED
data/todo.txt
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.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: 2025-
|
11
|
+
date: 2025-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,9 +96,9 @@ files:
|
|
96
96
|
- Rakefile
|
97
97
|
- examples/integration_tests.rb
|
98
98
|
- lib/ttytest.rb
|
99
|
+
- lib/ttytest/assertions.rb
|
99
100
|
- lib/ttytest/capture.rb
|
100
101
|
- lib/ttytest/constants.rb
|
101
|
-
- lib/ttytest/matchers.rb
|
102
102
|
- lib/ttytest/terminal.rb
|
103
103
|
- lib/ttytest/tmux/driver.rb
|
104
104
|
- lib/ttytest/tmux/session.rb
|