Allowing File#read to chunk IO
This commit is contained in:
parent
5deda9b456
commit
72e8ee62c7
@ -201,6 +201,7 @@ module FakeFS
|
||||
@mode = mode
|
||||
@file = FileSystem.find(path)
|
||||
@open = true
|
||||
@stream = StringIO.new(@file.content) if @file
|
||||
|
||||
check_valid_mode
|
||||
file_creation_mode? ? create_missing_file : check_file_existence!
|
||||
@ -211,11 +212,14 @@ module FakeFS
|
||||
@open = false
|
||||
end
|
||||
|
||||
def read
|
||||
def read(chunk = nil)
|
||||
raise IOError, 'closed stream' unless @open
|
||||
raise IOError, 'not opened for reading' if write_only?
|
||||
@stream.read(chunk)
|
||||
end
|
||||
|
||||
@file.content
|
||||
def rewind
|
||||
@stream.rewind
|
||||
end
|
||||
|
||||
def exists?
|
||||
|
@ -200,6 +200,19 @@ class FakeFSTest < Test::Unit::TestCase
|
||||
assert_equal 'Yada Yada', File.read(path)
|
||||
end
|
||||
|
||||
def test_can_chunk_io_when_reading
|
||||
path = '/path/to/file.txt'
|
||||
File.open(path, 'w') do |f|
|
||||
f << 'Yada Yada'
|
||||
end
|
||||
file = File.new(path, 'r')
|
||||
assert_equal 'Yada', file.read(4)
|
||||
assert_equal ' Yada', file.read(5)
|
||||
assert_equal '', file.read
|
||||
file.rewind
|
||||
assert_equal 'Yada Yada', file.read
|
||||
end
|
||||
|
||||
def test_can_get_size_of_files
|
||||
path = '/path/to/file.txt'
|
||||
File.open(path, 'w') do |f|
|
||||
|
Loading…
Reference in New Issue
Block a user