ttytest2 1.0.5 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ec106999c321d47e8f687ffe4d168088a5b4e23da1f84ff3c0be23597b95480
4
- data.tar.gz: e51ac6079575d1a5447510414ea345ca25afe2f421e02b5cea7dfbfc03a6d499
3
+ metadata.gz: 986b298bb959d217e338bd7ce6c6ad5640ee656b99c44a85358bd02d408524b2
4
+ data.tar.gz: '08f35657997cbad512a7251c895853249fa80342a7a338a7fd83c6dca7fc73f1'
5
5
  SHA512:
6
- metadata.gz: 513f344a96b541be8d422144cec5b6f57dfff62b071c341c3c251601c86299b73767054e411fc7b5a4324da608bcd33f6ad5a478f240c0d12f00e4d513c8537e
7
- data.tar.gz: c993ae268580440e8bdfb91c17a707638e6991a6842fa316cf72b6891d83af32ea8e8139a6a5bdc4f281c7fc1ec9d93c6159f2f49178bf8836978421caa276af
6
+ metadata.gz: 1df9f3105198994fddb7105892bb0a1a659832bd5de3ac0dca99c87f584ccd11eaa9a9f008be97071f318445b77cde6007c161260616f1f9cd6f55a7193fa239
7
+ data.tar.gz: 75ddbafbb51117a557e943bd63f7c6b3d908d0e5b3f58ac10f60dff5b9d11a17c29490974cd8a6f5d75c17b89a0320c004c4a2034120170346b089a661d19ee3
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  to push new version to github
2
- git tag v1.0.5
2
+ git tag v1.0.6
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.5.gem
7
+ gem push ttytest2-1.0.6.gem
data/todo.txt CHANGED
@@ -1,7 +1,2 @@
1
- assert_file_exists("./output.json")
2
- assert_file_not_exists("./tempfile")
3
- assert_file_contains("./log.txt", "Job completed")
4
- assert_file_permissions("./script.sh", "755")
5
-
6
1
  assert_exit_code(0) # For success
7
2
  assert_exit_code(1) # For expected failure
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.5
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-07-18 00:00:00.000000000 Z
11
+ date: 2025-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler