ttytest2 1.0.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 986b298bb959d217e338bd7ce6c6ad5640ee656b99c44a85358bd02d408524b2
4
- data.tar.gz: '08f35657997cbad512a7251c895853249fa80342a7a338a7fd83c6dca7fc73f1'
3
+ metadata.gz: 0ec86d17bfe3b3a9c9485f0b53c14f4dcfebd5e875dd2ba1de7f26c7ef4b1a87
4
+ data.tar.gz: 2b53db154e9c680b89897bc46cffe087d415ce22049727ec1b3ff698ce80aba0
5
5
  SHA512:
6
- metadata.gz: 1df9f3105198994fddb7105892bb0a1a659832bd5de3ac0dca99c87f584ccd11eaa9a9f008be97071f318445b77cde6007c161260616f1f9cd6f55a7193fa239
7
- data.tar.gz: 75ddbafbb51117a557e943bd63f7c6b3d908d0e5b3f58ac10f60dff5b9d11a17c29490974cd8a6f5d75c17b89a0320c004c4a2034120170346b089a661d19ee3
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,7 +2,7 @@
2
2
 
3
3
  module TTYtest
4
4
  # Assertions for ttytest2.
5
- module Matchers
5
+ module Assertions
6
6
  # Asserts the contents of a single row match the value expected
7
7
  # @param [Integer] row_number the row (starting from 0) to test against
8
8
  # @param [String] expected the expected value of the row. Any trailing whitespace is ignored
@@ -88,6 +88,7 @@ module TTYtest
88
88
  raise MatchError,
89
89
  "expected row #{row_number} to start with #{expected.inspect} and got #{get_inspection(actual)}\nEntire screen:\n#{self}"
90
90
  end
91
+ alias assert_line_starts_with assert_row_starts_with
91
92
 
92
93
  # Asserts the contents of a single row end with expected
93
94
  # @param [Integer] row_number the row (starting from 0) to test against
@@ -103,6 +104,7 @@ module TTYtest
103
104
  raise MatchError,
104
105
  "expected row #{row_number} to end with #{expected.inspect} and got #{get_inspection(actual)}\nEntire screen:\n#{self}"
105
106
  end
107
+ alias assert_line_ends_with assert_row_ends_with
106
108
 
107
109
  # Asserts the contents of a single row match against the passed in regular expression
108
110
  # @param [Integer] row_number the row (starting from 0) to test against
@@ -118,6 +120,7 @@ module TTYtest
118
120
  raise MatchError,
119
121
  "expected row #{row_number} to match regexp #{regexp_str} but it did not. Row value #{get_inspection(actual)}\nEntire screen:\n#{self}"
120
122
  end
123
+ alias assert_line_regexp assert_row_regexp
121
124
 
122
125
  # Asserts the contents of a multiple rows each match against the passed in regular expression
123
126
  # @param [Integer] row_start the row (starting from 0) to test against
@@ -136,6 +139,7 @@ module TTYtest
136
139
  "expected row #{index} to match regexp #{regexp_str} but it did not. Row value #{get_inspection(actual_row)}\nEntire screen:\n#{self}"
137
140
  end
138
141
  end
142
+ alias assert_line_each_match_regexp assert_rows_each_match_regexp
139
143
 
140
144
  # Asserts that the cursor is in the expected position
141
145
  # @param [Integer] x cursor x (row) position, starting from 0
@@ -165,29 +169,11 @@ module TTYtest
165
169
  raise MatchError, "expected cursor to be hidden was visible\nEntire screen:\n#{self}"
166
170
  end
167
171
 
168
- def matched(expected, actual)
169
- expected_rows = expected.split("\n")
170
- diff = []
171
- matched = true
172
- actual.each_with_index do |actual_row, index|
173
- expected_row = (expected_rows[index] || '').rstrip
174
- if actual_row != expected_row
175
- diff << "-#{expected_row}"
176
- diff << "+#{actual_row}"
177
- matched = false
178
- else
179
- diff << " #{actual_row}".rstrip
180
- end
181
- end
182
-
183
- [matched, diff]
184
- end
185
-
186
172
  # Asserts the full contents of the terminal
187
173
  # @param [String] expected the full expected contents of the terminal. Trailing whitespace on each line is ignored
188
174
  # @raise [MatchError] if the terminal doesn't match the expected content
189
175
  def assert_contents(expected)
190
- matched, diff = matched(expected, rows)
176
+ matched, diff = get_diff(expected, rows)
191
177
 
192
178
  return if matched
193
179
 
@@ -204,7 +190,7 @@ module TTYtest
204
190
  validate(row_end)
205
191
  row_end += 1 if row_end.zero?
206
192
 
207
- matched, diff = matched(expected, rows.slice(row_start, row_end))
193
+ matched, diff = get_diff(expected, rows.slice(row_start, row_end))
208
194
 
209
195
  return if matched
210
196
 
@@ -242,6 +228,7 @@ module TTYtest
242
228
  raise MatchError,
243
229
  "File with path #{file_path} did not contain #{needle}.\nEntire screen:\n#{self}"
244
230
  end
231
+ alias assert_file_like assert_file_contains
245
232
 
246
233
  def assert_file_has_permissions(file_path, permissions)
247
234
  raise file_not_found_error(file_path) unless File.exist?(file_path)
@@ -255,6 +242,17 @@ module TTYtest
255
242
  "File had permissions #{perms_octal}, not #{permissions} as expected.\n Entire screen:\n#{self}"
256
243
  end
257
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
+
258
256
  METHODS = public_instance_methods
259
257
 
260
258
  private
@@ -284,6 +282,24 @@ module TTYtest
284
282
  Entire screen:\n#{self}"
285
283
  end
286
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
+
287
303
  def file_not_found_error(file_path)
288
304
  raise MatchError,
289
305
  "File with path #{file_path} was not found when asserted it did exist.\nEntire screen:\n#{self}"
@@ -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::Matchers
10
+ include TTYtest::Assertions
11
11
 
12
12
  attr_reader :cursor_x, :cursor_y, :width, :height
13
13
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
- require 'ttytest/matchers'
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
- Matchers::METHODS.each do |matcher_name|
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '1.0.6'
4
+ VERSION = '1.0.7'
5
5
  end
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, :new_terminal, :new_default_sh_terminal, :new_sh_terminal
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
@@ -1,7 +1,7 @@
1
1
  to push new version to github
2
- git tag v1.0.6
2
+ git tag v1.0.7
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.6.gem
7
+ gem push ttytest2-1.0.7.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.6
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-07-28 00:00:00.000000000 Z
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