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