Class: CachedNestedFileReaderTest
- Defined in:
- lib/cached_nested_file_reader.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_caching_functionality ⇒ Object
- #test_readlines_with_imports ⇒ Object
- #test_readlines_without_imports ⇒ Object
Instance Method Details
#setup ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cached_nested_file_reader.rb', line 89 def setup @file2 = Tempfile.new('test2.txt') @file2.write("ImportedLine1\nImportedLine2") @file2.rewind @file1 = Tempfile.new('test1.txt') @file1.write("Line1\nLine2\n #insert #{@file2.path}\nLine3") @file1.rewind @reader = CachedNestedFileReader.new(import_pattern: /^(?<indention> *)#insert (?'name'.+)$/) end |
#teardown ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/cached_nested_file_reader.rb', line 100 def teardown @file1.close @file1.unlink @file2.close @file2.unlink end |
#test_caching_functionality ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/cached_nested_file_reader.rb', line 119 def test_caching_functionality # First read result1 = @reader.readlines(@file2.path).map(&:to_s) # Simulate file content change @file2.reopen(@file2.path, 'w') { |f| f.write('ChangedLine') } # Second read (should read from cache, not the changed file) result2 = @reader.readlines(@file2.path).map(&:to_s) assert_equal result1, result2 assert_equal %w[ImportedLine1 ImportedLine2], result2 end |
#test_readlines_with_imports ⇒ Object
113 114 115 116 117 |
# File 'lib/cached_nested_file_reader.rb', line 113 def test_readlines_with_imports result = @reader.readlines(@file1.path).map(&:to_s) assert_equal ['Line1', 'Line2', ' ImportedLine1', ' ImportedLine2', 'Line3'], result end |
#test_readlines_without_imports ⇒ Object
108 109 110 111 |
# File 'lib/cached_nested_file_reader.rb', line 108 def test_readlines_without_imports result = @reader.readlines(@file2.path).map(&:to_s) assert_equal %w[ImportedLine1 ImportedLine2], result end |