Module: FunWith::Testing::Assertions::FunWithFiles
- Defined in:
- lib/fun_with/testing/assertions/fun_with_files.rb
Instance Method Summary collapse
- #assert_directory(file, message = "") ⇒ Object
- #assert_empty_directory(file, message = "") ⇒ Object
- #assert_empty_file(file, message = "") ⇒ Object
- #assert_file(file, message = "") ⇒ Object
- #assert_file_contents(file, content, message = "") ⇒ Object
- #assert_file_has_content(file, message = "") ⇒ Object (also: #assert_file_not_empty)
- #assert_fwf_filepath(file, message = "") ⇒ Object
- #assert_no_file(file, message = "") ⇒ Object
- #assert_not_directory(file, message = "") ⇒ Object
Instance Method Details
#assert_directory(file, message = "") ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 33 def assert_directory( file, = "" ) assert_fwf_filepath( file, ) = ( , "<#{file}> should be a directory." ) safe_assert_block do file.directory? end end |
#assert_empty_directory(file, message = "") ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 65 def assert_empty_directory( file, = "" ) assert_fwf_filepath( file, ) = ( , "Empty directory should exist at <#{file}>." ) safe_assert_block do file.directory? && file.empty? end end |
#assert_empty_file(file, message = "") ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 55 def assert_empty_file( file, = "" ) assert_fwf_filepath( file, ) = ( , "Empty file should exist at <#{file}>." ) safe_assert_block do file.exist? && file.empty? end end |
#assert_file(file, message = "") ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 13 def assert_file( file, = "" ) assert_fwf_filepath( file, ) = ( , "File should exist at <#{file}>." ) safe_assert_block do file.exist? end end |
#assert_file_contents(file, content, message = "") ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 87 def assert_file_contents( file, content, = "" ) 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, ) when Regexp assert_match( content, file.read, ) end end |
#assert_file_has_content(file, message = "") ⇒ Object Also known as: assert_file_not_empty
75 76 77 78 79 80 81 82 83 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 75 def assert_file_has_content( file, = "" ) assert_fwf_filepath( file, ) = ( , "File should exist at <#{file}>, and have content." ) safe_assert_block do file.exist? && !file.empty? end end |
#assert_fwf_filepath(file, message = "") ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 5 def assert_fwf_filepath( file, = "" ) = ( , "File <#{file}> should be a FunWith::Files::FilePath") safe_assert_block do file.is_a?( FunWith::Files::FilePath ) end end |
#assert_no_file(file, message = "") ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 23 def assert_no_file( file, = "" ) assert_fwf_filepath( file, ) = ( , "No file/directory should exist at <#{file}>." ) safe_assert_block do ! file.exist? end end |
#assert_not_directory(file, message = "") ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fun_with/testing/assertions/fun_with_files.rb', line 44 def assert_not_directory( file, = "" ) assert_fwf_filepath( file, ) = ( , "<#{file}> shouldn't be a directory." ) safe_assert_block do ! file.directory? end end |