Module: FunWith::Testing::Assertions::FunWithFiles
- Defined in:
- lib/fun_with/testing/assertions/fun_with_files.rb
Instance Method Summary collapse
-
#assert_directory(file, msg = nil) ⇒ Object
The object given is a filepath, and points to a directory.
-
#assert_empty_directory(file, msg = nil) ⇒ Object
The object given is a filepath.
-
#assert_empty_file(file, msg = nil) ⇒ Object
The object given is a filepath.
-
#assert_file(file, msg = nil) ⇒ Object
The object given is an instance of class FilePath, and points to a file that exists.
- #assert_file_contents(file, content, msg = nil) ⇒ Object
-
#assert_file_has_content(file, msg = nil) ⇒ Object
(also: #assert_file_not_empty)
The object given is a filepath.
-
#assert_fwf_filepath(file, msg = nil) ⇒ Object
The object given must be an instance of class FilePath.
-
#assert_no_file(file, msg = nil) ⇒ Object
The object given is a filepath, but doesn’t point to an existing file or directory.
-
#assert_not_directory(file, msg = nil) ⇒ Object
The object given is a filepath, but doesn’t point to a directory.
Instance Method Details
#assert_directory(file, msg = nil) ⇒ Object
The object given is a filepath, and points to a directory
29 30 31 32 33 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 29 def assert_directory( file, msg = nil ) assert_fwf_filepath( file, msg ) msg = (msg){ "<#{file}> should be a directory." } assert file.directory?, msg end |
#assert_empty_directory(file, msg = nil) ⇒ Object
The object given is a filepath. It points to a directory that exists. That directory is empty.
54 55 56 57 58 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 54 def assert_empty_directory( file, msg = nil ) assert_fwf_filepath( file ) msg = (msg){ "Empty directory should exist at <#{file}>." } assert file.directory? && file.empty?, msg end |
#assert_empty_file(file, msg = nil) ⇒ Object
The object given is a filepath. It points to a file that exists. That file is empty.
45 46 47 48 49 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 45 def assert_empty_file( file, msg = nil ) assert_fwf_filepath( file ) msg = (msg){ "Empty file should exist at <#{file}>." } assert file.file? && file.empty?, msg end |
#assert_file(file, msg = nil) ⇒ Object
The object given is an instance of class FilePath, and points to a file that exists.
13 14 15 16 17 18 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 13 def assert_file( file, msg = nil ) assert_fwf_filepath( file, (nil){ "...is not a file." } ) msg = (msg){ "File should exist at <#{file}>." } assert file.file?, msg end |
#assert_file_contents(file, content, msg = nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 75 def assert_file_contents( file, content, msg = nil ) assert_file( file ) case content when String # message = build_message( message, "File <#{file}> contents should be #{content[0..99].inspect}#{'...(truncated)' if content.length > 100}" ) assert_equal( content, file.read, msg ) when Regexp assert_match( content, file.read, msg ) end end |
#assert_file_has_content(file, msg = nil) ⇒ Object Also known as: assert_file_not_empty
The object given is a filepath. It points to a file that exists. That file contains content.
64 65 66 67 68 69 70 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 64 def assert_file_has_content( file, msg = nil ) assert_fwf_filepath( file, ) msg = (msg){ "File should exist at <#{file}>, and have content." } assert file.exist?, msg.call + "(file does not exist)" assert file.file?, msg.call + "(not a file)" refute file.empty?, msg.call + "(file is not empty)" end |
#assert_fwf_filepath(file, msg = nil) ⇒ Object
The object given must be an instance of class FilePath
6 7 8 9 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 6 def assert_fwf_filepath( file, msg = nil ) msg = (msg){ "File <#{file}> should be a FunWith::Files::FilePath" } assert_kind_of FunWith::Files::FilePath, file, msg end |
#assert_no_file(file, msg = nil) ⇒ Object
The object given is a filepath, but doesn’t point to an existing file or directory.
22 23 24 25 26 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 22 def assert_no_file( file, msg = nil ) assert_fwf_filepath( file, ) msg = (msg){ "No file/directory should exist at <#{file}>." } refute file.file?, msg end |
#assert_not_directory(file, msg = nil) ⇒ Object
The object given is a filepath, but doesn’t point to a directory.
36 37 38 39 40 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 36 def assert_not_directory( file, msg = nil ) assert_fwf_filepath( file, ) msg = (msg){ "<#{file}> shouldn't be a directory." } refute file.directory? end |