ttytest2 1.0.2 → 1.0.3
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 +59 -20
- data/lib/ttytest/version.rb +1 -1
- data/notes.txt +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a0efe35a9376c501403b55279be2f4d1945cd11fa6daf56df854f1883d432df
|
4
|
+
data.tar.gz: 8663d5d7aad9d17067733670cec372fe6d9ea0c1e384956a4e899da9b0322054
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7962a743edd2522bfe4d5278f2ef014dde6f2b086d022ed9a9193101b30e4eea27dcbb986db43e24032e0beb51380b27724d3c50323b8f0df9c143e1f09d6110
|
7
|
+
data.tar.gz: 91d8b71eead9a642318f10ef2209cc3775d3fb82f14456e4976955fd868fe85e33a34e271f5e5d39fd80577be23a85fcc3279e9c8d831a3907513eabd8112b70
|
data/lib/ttytest/matchers.rb
CHANGED
@@ -3,33 +3,61 @@
|
|
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
|
+
|
6
31
|
# Asserts the contents of a single row match the value expected
|
7
32
|
# @param [Integer] row_number the row (starting from 0) to test against
|
8
33
|
# @param [String] expected the expected value of the row. Any trailing whitespace is ignored
|
9
34
|
# @raise [MatchError] if the row doesn't match exactly
|
10
35
|
def assert_row(row_number, expected)
|
36
|
+
validate(row_number)
|
11
37
|
expected = expected.rstrip
|
12
38
|
actual = row(row_number)
|
13
39
|
|
14
|
-
return if actual == expected
|
40
|
+
return if !actual.nil? && actual == expected
|
15
41
|
|
16
42
|
raise MatchError,
|
17
|
-
"expected row #{row_number} to be #{expected.inspect} but got #{actual
|
18
|
-
|
19
|
-
|
20
|
-
def assert_last_row(expected)
|
43
|
+
"expected row #{row_number} to be #{expected.inspect} but got #{get_inspection(actual)}\n
|
44
|
+
Entire screen:\n#{self}"
|
21
45
|
end
|
46
|
+
alias assert_line assert_row
|
22
47
|
|
23
48
|
# Asserts the specified row is empty
|
24
49
|
# @param [Integer] row_number the row (starting from 0) to test against
|
25
50
|
# @raise [MatchError] if the row isn't empty
|
26
51
|
def assert_row_is_empty(row_number)
|
52
|
+
validate(row_number)
|
27
53
|
actual = row(row_number)
|
28
54
|
|
29
55
|
return if actual == ''
|
30
56
|
|
31
|
-
raise MatchError,
|
57
|
+
raise MatchError,
|
58
|
+
"expected row #{row_number} to be empty but got #{get_inspection(actual)}\nEntire screen:\n#{self}"
|
32
59
|
end
|
60
|
+
alias assert_line_is_empty assert_row_is_empty
|
33
61
|
|
34
62
|
# Asserts the contents of a single row contains the expected string at a specific position
|
35
63
|
# @param [Integer] row_number the row (starting from 0) to test against
|
@@ -38,45 +66,52 @@ module TTYtest
|
|
38
66
|
# @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
|
39
67
|
# @raise [MatchError] if the row doesn't match
|
40
68
|
def assert_row_at(row_number, column_start, column_end, expected)
|
69
|
+
validate(row_number)
|
41
70
|
expected = expected.rstrip
|
42
71
|
actual = row(row_number)
|
43
72
|
column_end += 1
|
44
73
|
|
45
|
-
return if actual[column_start, column_end].eql?(expected)
|
74
|
+
return if !actual.nil? && actual[column_start, column_end].eql?(expected)
|
75
|
+
|
76
|
+
inspection = get_inspection_bounded(actual, column_start, column_end)
|
46
77
|
|
47
78
|
raise MatchError,
|
48
79
|
"expected row #{row_number} to contain #{expected[column_start,
|
49
|
-
column_end]} at #{column_start}-#{column_end} and got #{
|
50
|
-
column_end]}\nEntire screen:\n#{self}"
|
80
|
+
column_end]} at #{column_start}-#{column_end} and got #{inspection}\nEntire screen:\n#{self}"
|
51
81
|
end
|
82
|
+
alias assert_line_at assert_row_at
|
52
83
|
|
53
84
|
# Asserts the contents of a single row contains the value expected
|
54
85
|
# @param [Integer] row_number the row (starting from 0) to test against
|
55
86
|
# @param [String] expected the expected value contained in the row. Any trailing whitespace is ignored
|
56
87
|
# @raise [MatchError] if the row doesn't match
|
57
88
|
def assert_row_like(row_number, expected)
|
89
|
+
validate(row_number)
|
58
90
|
expected = expected.rstrip
|
59
91
|
actual = row(row_number)
|
60
92
|
|
61
|
-
return if actual.include?(expected)
|
93
|
+
return if !actual.nil? && actual.include?(expected)
|
62
94
|
|
63
95
|
raise MatchError,
|
64
|
-
"expected row #{row_number} to be like #{expected.inspect} but got #{actual
|
96
|
+
"expected row #{row_number} to be like #{expected.inspect} but got #{get_inspection(actual)}\nEntire screen:\n#{self}"
|
65
97
|
end
|
66
98
|
alias assert_row_contains assert_row_like
|
99
|
+
alias assert_line_contains assert_row_like
|
100
|
+
alias assert_line_like assert_row_like
|
67
101
|
|
68
102
|
# Asserts the contents of a single row starts with expected string
|
69
103
|
# @param [Integer] row_number the row (starting from 0) to test against
|
70
104
|
# @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
|
71
105
|
# @raise [MatchError] if the row doesn't match
|
72
106
|
def assert_row_starts_with(row_number, expected)
|
107
|
+
validate(row_number)
|
73
108
|
expected = expected.rstrip
|
74
109
|
actual = row(row_number)
|
75
110
|
|
76
|
-
return if actual.start_with?(expected)
|
111
|
+
return if !actual.nil? && actual.start_with?(expected)
|
77
112
|
|
78
113
|
raise MatchError,
|
79
|
-
"expected row #{row_number} to start with #{expected.inspect} and got #{actual
|
114
|
+
"expected row #{row_number} to start with #{expected.inspect} and got #{get_inspection(actual)}\nEntire screen:\n#{self}"
|
80
115
|
end
|
81
116
|
|
82
117
|
# Asserts the contents of a single row end with expected
|
@@ -84,13 +119,14 @@ module TTYtest
|
|
84
119
|
# @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
|
85
120
|
# @raise [MatchError] if the row doesn't match
|
86
121
|
def assert_row_ends_with(row_number, expected)
|
122
|
+
validate(row_number)
|
87
123
|
expected = expected.rstrip
|
88
124
|
actual = row(row_number)
|
89
125
|
|
90
|
-
return if actual.end_with?(expected)
|
126
|
+
return if !actual.nil? && actual.end_with?(expected)
|
91
127
|
|
92
128
|
raise MatchError,
|
93
|
-
"expected row #{row_number} to end with #{expected.inspect} and got #{actual
|
129
|
+
"expected row #{row_number} to end with #{expected.inspect} and got #{get_inspection(actual)}\nEntire screen:\n#{self}"
|
94
130
|
end
|
95
131
|
|
96
132
|
# Asserts the contents of a single row match against the passed in regular expression
|
@@ -98,13 +134,14 @@ module TTYtest
|
|
98
134
|
# @param [String] regexp_str the regular expression as a string that will be used to match with.
|
99
135
|
# @raise [MatchError] if the row doesn't match against the regular expression
|
100
136
|
def assert_row_regexp(row_number, regexp_str)
|
137
|
+
validate(row_number)
|
101
138
|
regexp = Regexp.new(regexp_str)
|
102
139
|
actual = row(row_number)
|
103
140
|
|
104
|
-
return if actual.match?(regexp)
|
141
|
+
return if !actual.nil? && actual.match?(regexp)
|
105
142
|
|
106
143
|
raise MatchError,
|
107
|
-
"expected row #{row_number} to match regexp #{regexp_str} but it did not. Row value #{actual
|
144
|
+
"expected row #{row_number} to match regexp #{regexp_str} but it did not. Row value #{get_inspection(actual)}\nEntire screen:\n#{self}"
|
108
145
|
end
|
109
146
|
|
110
147
|
# Asserts the contents of a multiple rows each match against the passed in regular expression
|
@@ -113,14 +150,15 @@ module TTYtest
|
|
113
150
|
# @param [String] regexp_str the regular expression as a string that will be used to match with.
|
114
151
|
# @raise [MatchError] if the row doesn't match against the regular expression
|
115
152
|
def assert_rows_each_match_regexp(row_start, row_end, regexp_str)
|
153
|
+
validate(row_end)
|
116
154
|
regexp = Regexp.new(regexp_str)
|
117
155
|
row_end += 1 if row_end.zero?
|
118
156
|
|
119
157
|
rows.slice(row_start, row_end).each_with_index do |actual_row, index|
|
120
|
-
next if actual_row.match?(regexp)
|
158
|
+
next if !actual_row.nil? && actual_row.match?(regexp)
|
121
159
|
|
122
160
|
raise MatchError,
|
123
|
-
"expected row #{index} to match regexp #{regexp_str} but it did not. Row value #{actual_row
|
161
|
+
"expected row #{index} to match regexp #{regexp_str} but it did not. Row value #{get_inspection(actual_row)}\nEntire screen:\n#{self}"
|
124
162
|
end
|
125
163
|
end
|
126
164
|
|
@@ -135,7 +173,7 @@ module TTYtest
|
|
135
173
|
return if actual == expected
|
136
174
|
|
137
175
|
raise MatchError,
|
138
|
-
"expected cursor to be at #{expected.inspect} but was at #{actual
|
176
|
+
"expected cursor to be at #{expected.inspect} but was at #{get_inspection(actual)}\nEntire screen:\n#{self}"
|
139
177
|
end
|
140
178
|
|
141
179
|
# @raise [MatchError] if the cursor is hidden
|
@@ -188,6 +226,7 @@ module TTYtest
|
|
188
226
|
# @param [String] expected the expected contents of the terminal at specified rows. Trailing whitespace on each line is ignored
|
189
227
|
# @raise [MatchError] if the terminal doesn't match the expected content
|
190
228
|
def assert_contents_at(row_start, row_end, expected)
|
229
|
+
validate(row_end)
|
191
230
|
row_end += 1 if row_end.zero?
|
192
231
|
|
193
232
|
matched, diff = matched(expected, rows.slice(row_start, row_end))
|
data/lib/ttytest/version.rb
CHANGED
data/notes.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.3
|
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-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|