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
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/cached_nested_file_reader.rb', line 85 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: /^ *#insert (?'name'.+)$/) end |
#teardown ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/cached_nested_file_reader.rb', line 96 def teardown @file1.close @file1.unlink @file2.close @file2.unlink end |
#test_caching_functionality ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cached_nested_file_reader.rb', line 115 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
109 110 111 112 113 |
# File 'lib/cached_nested_file_reader.rb', line 109 def test_readlines_with_imports result = @reader.readlines(@file1.path).map(&:to_s) assert_equal %w[Line1 Line2 ImportedLine1 ImportedLine2 Line3], result end |
#test_readlines_without_imports ⇒ Object
104 105 106 107 |
# File 'lib/cached_nested_file_reader.rb', line 104 def test_readlines_without_imports result = @reader.readlines(@file2.path).map(&:to_s) assert_equal %w[ImportedLine1 ImportedLine2], result end |