Module: TTYtest::FileAssertions
- Included in:
- Assertions
- Defined in:
- lib/ttytest/assertions/file_assertions.rb
Overview
File Assertions for ttytest2.
Instance Method Summary collapse
-
#assert_file_contains(file_path, needle) ⇒ Object
(also: #assert_file_like)
Asserts the specified file contains the passed in string value.
-
#assert_file_doesnt_exist(file_path) ⇒ Object
Asserts the specified file does not exists.
-
#assert_file_exists(file_path) ⇒ Object
Asserts the specified file exists.
-
#assert_file_has_line_count(file_path, expected_count) ⇒ Object
Asserts the specified file has line count specified.
-
#assert_file_has_permissions(file_path, permissions) ⇒ Object
Asserts the specified file has the permissions specified.
Instance Method Details
#assert_file_contains(file_path, needle) ⇒ Object Also known as: assert_file_like
Asserts the specified file contains the passed in string value
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ttytest/assertions/file_assertions.rb', line 28 def assert_file_contains(file_path, needle) raise file_not_found_error(file_path) unless File.exist?(file_path) raise file_is_dir_error(file_path) unless File.file?(file_path) file_contains = false File.foreach(file_path) do |line| if line.include?(needle) file_contains = true break end end return if file_contains raise MatchError, "File with path #{file_path} did not contain #{needle}.\nEntire screen:\n#{self}" end |
#assert_file_doesnt_exist(file_path) ⇒ Object
Asserts the specified file does not exists
17 18 19 20 21 22 |
# File 'lib/ttytest/assertions/file_assertions.rb', line 17 def assert_file_doesnt_exist(file_path) return unless File.exist?(file_path) || File.file?(file_path) raise MatchError, "File with path #{file_path} was found or is a directory when it was asserted it did not exist.\nEntire screen:\n#{self}" end |
#assert_file_exists(file_path) ⇒ Object
Asserts the specified file exists
9 10 11 12 |
# File 'lib/ttytest/assertions/file_assertions.rb', line 9 def assert_file_exists(file_path) raise file_not_found_error(file_path) unless File.exist?(file_path) raise file_is_dir_error(file_path) unless File.file?(file_path) end |
#assert_file_has_line_count(file_path, expected_count) ⇒ Object
Asserts the specified file has line count specified
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ttytest/assertions/file_assertions.rb', line 66 def assert_file_has_line_count(file_path, expected_count) raise file_not_found_error(file_path) unless File.exist?(file_path) raise file_is_dir_error(file_path) unless File.file?(file_path) actual_count = File.foreach(file_path).count return if actual_count == expected_count raise MatchError, "File had #{actual_count} lines, not #{expected_count} lines as expected.\nEntire screen:\n#{self}" end |
#assert_file_has_permissions(file_path, permissions) ⇒ Object
Asserts the specified file has the permissions specified
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ttytest/assertions/file_assertions.rb', line 50 def (file_path, ) raise file_not_found_error(file_path) unless File.exist?(file_path) raise file_is_dir_error(file_path) unless File.file?(file_path) file_mode = File.stat(file_path).mode perms_octal = format('%o', file_mode)[-3...] return if perms_octal == raise MatchError, "File had permissions #{perms_octal}, not #{} as expected.\n Entire screen:\n#{self}" end |