ttytest2 1.0.4 → 1.0.6
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/lib/ttytest/matchers.rb +78 -25
- data/lib/ttytest/terminal.rb +2 -2
- data/lib/ttytest/tmux/driver.rb +12 -3
- data/lib/ttytest/version.rb +1 -1
- data/notes.txt +2 -2
- data/todo.txt +2 -0
- data/ttytest2.gemspec +2 -2
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 986b298bb959d217e338bd7ce6c6ad5640ee656b99c44a85358bd02d408524b2
|
4
|
+
data.tar.gz: '08f35657997cbad512a7251c895853249fa80342a7a338a7fd83c6dca7fc73f1'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1df9f3105198994fddb7105892bb0a1a659832bd5de3ac0dca99c87f584ccd11eaa9a9f008be97071f318445b77cde6007c161260616f1f9cd6f55a7193fa239
|
7
|
+
data.tar.gz: 75ddbafbb51117a557e943bd63f7c6b3d908d0e5b3f58ac10f60dff5b9d11a17c29490974cd8a6f5d75c17b89a0320c004c4a2034120170346b089a661d19ee3
|
data/lib/ttytest/matchers.rb
CHANGED
@@ -3,31 +3,6 @@
|
|
3
3
|
module TTYtest
|
4
4
|
# Assertions for ttytest2.
|
5
5
|
module Matchers
|
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
|
-
|
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
|
@@ -239,6 +214,84 @@ module TTYtest
|
|
239
214
|
alias assert_matches_at assert_contents_at
|
240
215
|
alias assert_rows assert_contents_at
|
241
216
|
|
217
|
+
def assert_file_exists(file_path)
|
218
|
+
raise file_not_found_error(file_path) unless File.exist?(file_path)
|
219
|
+
raise file_is_dir_error(file_path) unless File.file?(file_path)
|
220
|
+
end
|
221
|
+
|
222
|
+
def assert_file_doesnt_exist(file_path)
|
223
|
+
return unless File.exist?(file_path) || File.file?(file_path)
|
224
|
+
|
225
|
+
raise MatchError,
|
226
|
+
"File with path #{file_path} was found or is a directory when it was asserted it did not exist.\nEntire screen:\n#{self}"
|
227
|
+
end
|
228
|
+
|
229
|
+
def assert_file_contains(file_path, needle)
|
230
|
+
raise file_not_found_error(file_path) unless File.exist?(file_path)
|
231
|
+
raise file_is_dir_error(file_path) unless File.file?(file_path)
|
232
|
+
|
233
|
+
file_contains = false
|
234
|
+
File.foreach(file_path) do |line|
|
235
|
+
if line.include?(needle)
|
236
|
+
file_contains = true
|
237
|
+
break
|
238
|
+
end
|
239
|
+
end
|
240
|
+
return if file_contains
|
241
|
+
|
242
|
+
raise MatchError,
|
243
|
+
"File with path #{file_path} did not contain #{needle}.\nEntire screen:\n#{self}"
|
244
|
+
end
|
245
|
+
|
246
|
+
def assert_file_has_permissions(file_path, permissions)
|
247
|
+
raise file_not_found_error(file_path) unless File.exist?(file_path)
|
248
|
+
raise file_is_dir_error(file_path) unless File.file?(file_path)
|
249
|
+
|
250
|
+
file_mode = File.stat(file_path).mode
|
251
|
+
perms_octal = format('%o', file_mode)[-3...]
|
252
|
+
return if perms_octal == permissions
|
253
|
+
|
254
|
+
raise MatchError,
|
255
|
+
"File had permissions #{perms_octal}, not #{permissions} as expected.\n Entire screen:\n#{self}"
|
256
|
+
end
|
257
|
+
|
242
258
|
METHODS = public_instance_methods
|
259
|
+
|
260
|
+
private
|
261
|
+
|
262
|
+
def get_inspection(actual)
|
263
|
+
if actual.nil?
|
264
|
+
'nil'
|
265
|
+
else
|
266
|
+
actual.inspect
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def get_inspection_bounded(actual, column_start, column_end)
|
271
|
+
if actual.nil?
|
272
|
+
'nil'
|
273
|
+
else
|
274
|
+
actual[column_start, column_end]
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def validate(row)
|
279
|
+
return if @height.nil?
|
280
|
+
return unless row >= @height
|
281
|
+
|
282
|
+
raise MatchError,
|
283
|
+
"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
|
284
|
+
Entire screen:\n#{self}"
|
285
|
+
end
|
286
|
+
|
287
|
+
def file_not_found_error(file_path)
|
288
|
+
raise MatchError,
|
289
|
+
"File with path #{file_path} was not found when asserted it did exist.\nEntire screen:\n#{self}"
|
290
|
+
end
|
291
|
+
|
292
|
+
def file_is_dir_error(file_path)
|
293
|
+
raise MatchError,
|
294
|
+
"File with path #{file_path} is a directory.\nEntire screen:\n#{self}"
|
295
|
+
end
|
243
296
|
end
|
244
297
|
end
|
data/lib/ttytest/terminal.rb
CHANGED
@@ -194,9 +194,9 @@ module TTYtest
|
|
194
194
|
:cursor_visible?, :cursor_hidden?
|
195
195
|
|
196
196
|
Matchers::METHODS.each do |matcher_name|
|
197
|
-
define_method matcher_name do |*args|
|
197
|
+
define_method matcher_name do |*args, **kwargs|
|
198
198
|
synchronize do
|
199
|
-
capture.public_send(matcher_name, *args)
|
199
|
+
capture.public_send(matcher_name, *args, **kwargs)
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
data/lib/ttytest/tmux/driver.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'open3'
|
4
4
|
require 'securerandom'
|
5
|
+
require 'English'
|
5
6
|
|
6
7
|
require 'ttytest/terminal'
|
7
8
|
require 'ttytest/tmux/session'
|
@@ -52,10 +53,18 @@ module TTYtest
|
|
52
53
|
ensure_available
|
53
54
|
puts "tmux(#{args.inspect[1...-1]})" if debug?
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
cmd = [@tmux_cmd, '-L', SOCKET_NAME, *args]
|
57
|
+
output = nil
|
58
|
+
status = nil
|
59
|
+
IO.popen(cmd, err: %i[child out]) do |io|
|
60
|
+
output = io.read
|
61
|
+
io.close
|
62
|
+
status = $CHILD_STATUS
|
63
|
+
end
|
57
64
|
|
58
|
-
|
65
|
+
raise TmuxError, "tmux(#{args.inspect[1...-1]}) failed\n#{output}" unless status&.success?
|
66
|
+
|
67
|
+
output
|
59
68
|
end
|
60
69
|
|
61
70
|
def available?
|
data/lib/ttytest/version.rb
CHANGED
data/notes.txt
CHANGED
data/todo.txt
ADDED
data/ttytest2.gemspec
CHANGED
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.required_ruby_version = '>= 3.2.3'
|
26
26
|
|
27
|
-
spec.add_development_dependency 'bundler'
|
27
|
+
spec.add_development_dependency 'bundler'
|
28
28
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
29
29
|
spec.add_development_dependency 'open3', '~> 0.2'
|
30
|
-
spec.add_development_dependency 'rake'
|
30
|
+
spec.add_development_dependency 'rake'
|
31
31
|
spec.add_development_dependency 'yard', '~> 0.9'
|
32
32
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
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.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: 2025-
|
11
|
+
date: 2025-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/ttytest/tmux/tmux.conf
|
106
106
|
- lib/ttytest/version.rb
|
107
107
|
- notes.txt
|
108
|
+
- todo.txt
|
108
109
|
- ttytest2.gemspec
|
109
110
|
homepage: https://github.com/a-eski/ttytest2
|
110
111
|
licenses:
|