ttytest2 1.4.0 → 1.5.0

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: 360be4f6d7358f00c2462a247939072ab8e93e1b64f9465112c62b6f9a22a484
4
- data.tar.gz: 7ede22ea96c9ce32546111761d730c008da042b997914e59b6d63bf1e4b06d69
3
+ metadata.gz: c7bf4ac747757d3aeaf01d103d15708cf487834ed43b9e3dad90e0d94e5203bc
4
+ data.tar.gz: 901c844e8719e6652943aae004e5f3deada174c4ab312e2e1c5956f496aa64c0
5
5
  SHA512:
6
- metadata.gz: 739fde4fb24d1a2a2a6179c5433be0191587f6e6f4aad92c495880991140569ad82821e8e3285bca1cd908f067adb3d404fd70c696b8cb1d973ee4d3fbb8349a
7
- data.tar.gz: 7c4472bb3d2cebfbbcf29edb62cbee8f16c8ae84bcd59e8263c108f71e0db89da1ab7fdd1c9c8dfa06f2047b9bae8d7e9e0016718a9ddcfb2ac89d91407efe10
6
+ metadata.gz: '02128e6d6ada7be932b624b5dd48c4d7eef0ace8a3d727629f7c756f4e5b0027b00aa6fe96040a38ff84178e0b74256e644584376e8d6784c48728662e50af3d'
7
+ data.tar.gz: a2909a072f201511eed7e77b72a67143b0fb9caa2dac07aa583696aa040e88c34a2188644b1a0872d4309cfe8b2ef7e30d271a68b97f298b4334948dd879a3a6
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2016-2025 John Hawthorn
2
+ Copyright (c) 2024-2025 Alex Eski
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -116,6 +116,8 @@ If you are reading this on github, the ruby docs accessible from [RubyDoc.Info](
116
116
 
117
117
  ### Available Assertions
118
118
 
119
+ #### Row Assertions
120
+
119
121
  * `assert_row(row_number, expected_text)`
120
122
 
121
123
  * `assert_row_is_empty(row_number)`
@@ -132,18 +134,32 @@ If you are reading this on github, the ruby docs accessible from [RubyDoc.Info](
132
134
 
133
135
  * `assert_rows_each_match_regexp(row_start, row_end, regexp_str)`
134
136
 
137
+ #### Column Assertions
138
+
135
139
  * `assert_column(col_number, expected_text)`
136
140
 
137
141
  * `assert_column_is_empty(col_number)`
138
142
 
139
143
  * `assert_column_at(col_number, row_start, row_end, expected_str)`
140
144
 
145
+ * `assert_column_starts_with(col_number, expected_text)`
146
+
147
+ * `assert_column_ends_with(col_number, expected_text)`
148
+
149
+ * `assert_column_regexp(col_number, regexp_str)`
150
+
151
+ * `assert_columns_each_match_regexp(col_start, col_end, regexp_str)`
152
+
153
+ #### Cursor Assertions
154
+
141
155
  * `assert_cursor_position(x: x, y: y)`
142
156
 
143
157
  * `assert_cursor_visible`
144
158
 
145
159
  * `assert_cursor_hidden`
146
160
 
161
+ #### Screen Contents Assertions
162
+
147
163
  * `assert_contents(lines_of_terminal)`
148
164
 
149
165
  * `assert_contents_at(row_start, row_end, expected_text)`
@@ -154,6 +170,8 @@ If you are reading this on github, the ruby docs accessible from [RubyDoc.Info](
154
170
 
155
171
  * `assert_contents_match_regexp(regexp_str)`
156
172
 
173
+ #### File Assertions
174
+
157
175
  * `assert_file_exists(file_path)`
158
176
 
159
177
  * `assert_file_doesnt_exist(file_path)`
@@ -42,7 +42,7 @@ module TTYtest
42
42
  # @param [Integer] col_number the column (starting from 0) to test against
43
43
  # @param [Integer] row_start the row position to start comparing expected against
44
44
  # @param [Integer] row_end the row position to end comparing expected against (inclusive)
45
- # @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
45
+ # @param [String] expected the expected value that the column starts with. Any trailing whitespace is ignored
46
46
  # @raise [MatchError] if the column doesn't match
47
47
  def assert_column_at(col_number, row_start, row_end, expected)
48
48
  validate(col_number)
@@ -51,7 +51,7 @@ module TTYtest
51
51
 
52
52
  rows.each_with_index do |row, i|
53
53
  next if i < row_start
54
- break if i > row_end || row.nil? || row == ''
54
+ break if i > row_end || row.nil?
55
55
 
56
56
  actual[i - row_start] = row[col_number]
57
57
  next if row[col_number] == expected[i - row_start]
@@ -68,5 +68,101 @@ module TTYtest
68
68
  raise MatchError,
69
69
  "expected column #{col_number} to contain #{expected} at #{row_start}-#{row_end} and got #{inspection}\nEntire screen:\n#{self}"
70
70
  end
71
+
72
+ # Asserts the contents of a single column contains the value expected
73
+ # @param [Integer] col_number the column number (starting from 0) to test against
74
+ # @param [String] expected the expected value contained in the column. Any trailing whitespace is ignored
75
+ # @raise [MatchError] if the column doesn't match
76
+ def assert_column_like(col_number, expected)
77
+ validate(col_number)
78
+ expected = expected.rstrip
79
+ actual = get_column(col_number).join
80
+
81
+ return if !actual.nil? && actual.include?(expected)
82
+
83
+ raise MatchError,
84
+ "expected column #{col_number} to be like #{expected.inspect} but got #{get_inspection(actual)}\nEntire screen:\n#{self}"
85
+ end
86
+ alias assert_column_contains assert_column_like
87
+
88
+ # Asserts the contents of a single column starts with expected string
89
+ # @param [Integer] col_number the column (starting from 0) to test against
90
+ # @param [String] expected the expected value that the column starts with. Any trailing whitespace is ignored
91
+ # @raise [MatchError] if the column doesn't match
92
+ def assert_column_starts_with(col_number, expected)
93
+ validate(col_number)
94
+ expected = expected.rstrip
95
+ actual = get_column(col_number).join
96
+
97
+ return if !actual.nil? && actual.start_with?(expected)
98
+
99
+ raise MatchError,
100
+ "expected column #{col_number} to start with #{expected.inspect} and got #{get_inspection(actual)}\nEntire screen:\n#{self}"
101
+ end
102
+
103
+ # Asserts the contents of a column ends with expected
104
+ # @param [Integer] col_number the column (starting from 0) to test against
105
+ # @param [String] expected the expected value that the column starts with. Any trailing whitespace is ignored
106
+ # @raise [MatchError] if the column doesn't match
107
+ def assert_column_ends_with(col_number, expected)
108
+ validate(col_number)
109
+ expected = expected.rstrip
110
+ actual = get_column(col_number).join
111
+
112
+ return if !actual.nil? && actual.end_with?(expected)
113
+
114
+ raise MatchError,
115
+ "expected column #{col_number} to end with #{expected.inspect} and got #{get_inspection(actual)}\nEntire screen:\n#{self}"
116
+ end
117
+
118
+ # Asserts the contents of a single column match against the passed in regular expression
119
+ # @param [Integer] col_number the column (starting from 0) to test against
120
+ # @param [String] regexp_str the regular expression as a string that will be used to match with.
121
+ # @raise [MatchError] if the column doesn't match against the regular expression
122
+ def assert_column_regexp(col_number, regexp_str)
123
+ validate(col_number)
124
+ regexp = Regexp.new(regexp_str)
125
+ actual = get_column(col_number).join
126
+
127
+ return if !actual.nil? && actual.match?(regexp)
128
+
129
+ raise MatchError,
130
+ "expected column #{col_number} to match regexp #{regexp_str} but it did not. Column value #{get_inspection(actual)}\nEntire screen:\n#{self}"
131
+ end
132
+
133
+ # Asserts the contents of a multiple columns each match against the passed in regular expression
134
+ # @param [Integer] col_start the column (starting from 0) to test against
135
+ # @param [Integer] col_end the last column to test against
136
+ # @param [String] regexp_str the regular expression as a string that will be used to match with.
137
+ # @raise [MatchError] if the column doesn't match against the regular expression
138
+ def assert_columns_each_match_regexp(col_start, col_end, regexp_str)
139
+ validate(col_end)
140
+ regexp = Regexp.new(regexp_str)
141
+ col_cur = col_start
142
+ col_end += 1 if col_end.zero?
143
+
144
+ while col_cur < col_end
145
+ actual = get_column(col_cur).join
146
+ col_cur += 1
147
+ next if !actual.nil? && actual.match?(regexp)
148
+
149
+ raise MatchError,
150
+ "expected column #{col_cur - 1} to match regexp #{regexp_str} but it did not. Column value #{get_inspection(actual)}\nEntire screen:\n#{self}"
151
+ end
152
+ end
153
+
154
+ private
155
+
156
+ def get_column(col_number)
157
+ actual = []
158
+
159
+ rows.each_with_index do |row, i|
160
+ break if row.nil?
161
+
162
+ actual[i] = row[col_number]
163
+ end
164
+
165
+ actual
166
+ end
71
167
  end
72
168
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TTYtest
4
+ # Exit Code Assertions for ttytest2. Not finished and added yet.
5
+ module ExitCodeAssertions
6
+ # Asserts that the exit code of the previous command matches the specified value
7
+ # Note: if you are tracking current row in your tests, this command will take up 2 lines.
8
+ # It echos the previous commands exit code to the screen and then reads it from there
9
+ # @param [Integer] code the expected exit code
10
+ # @raise [MatchError] if the exit code found does not match specified value
11
+ def assert_exit_code(code) end
12
+ end
13
+ end
@@ -61,7 +61,7 @@ module TTYtest
61
61
 
62
62
  # Asserts the specified file has line count specified
63
63
  # @param [String] file_path the path to the file
64
- # @param [String] expected_count the expected line count of the file
64
+ # @param [Integer] expected_count the expected line count of the file
65
65
  # @raise [MatchError] if the file has a different line count than specified
66
66
  def assert_file_has_line_count(file_path, expected_count)
67
67
  raise file_not_found_error(file_path) unless File.exist?(file_path)
@@ -89,7 +89,7 @@ module TTYtest
89
89
  end
90
90
  alias assert_line_starts_with assert_row_starts_with
91
91
 
92
- # Asserts the contents of a single row end with expected
92
+ # Asserts the contents of a single row ends with expected
93
93
  # @param [Integer] row_number the row (starting from 0) to test against
94
94
  # @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
95
95
  # @raise [MatchError] if the row doesn't match
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '1.4.0'
4
+ VERSION = '1.5.0'
5
5
  end
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  to push new version to github
2
- git tag v1.4.0
2
+ git tag v1.5.0
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.4.0.gem
7
+ gem push ttytest2-1.5.0.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.4.0
4
+ version: 1.5.0
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-09-29 00:00:00.000000000 Z
11
+ date: 2025-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,6 +92,7 @@ files:
92
92
  - ".github/workflows/test.yml"
93
93
  - ".gitignore"
94
94
  - Gemfile
95
+ - LICENSE
95
96
  - README.md
96
97
  - Rakefile
97
98
  - examples/integration_tests.rb
@@ -100,6 +101,7 @@ files:
100
101
  - lib/ttytest/assertions.rb
101
102
  - lib/ttytest/assertions/column_assertions.rb
102
103
  - lib/ttytest/assertions/cursor_assertions.rb
104
+ - lib/ttytest/assertions/exit_code_assertions.rb
103
105
  - lib/ttytest/assertions/file_assertions.rb
104
106
  - lib/ttytest/assertions/row_assertions.rb
105
107
  - lib/ttytest/assertions/screen_assertions.rb