File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,14 @@ def readline(sep_or_limit=$/, limit=Float::INFINITY)
127
127
return line
128
128
end
129
129
130
+ # Resets position to beginning of file
131
+ def rewind
132
+ @pos = 0
133
+ @real_pos = 0
134
+ @real_eof = false
135
+ @buffer = ""
136
+ end
137
+
130
138
# Writes the given data to the stream, incrementing the file position and
131
139
# returning the number of bytes written.
132
140
def write ( data )
Original file line number Diff line number Diff line change @@ -133,6 +133,15 @@ def test_readline_should_raise_exception_on_EOF
133
133
assert_raises ( EOFError ) { @file . readline }
134
134
end
135
135
136
+ def test_rewind_should_reset_to_beginning_of_file
137
+ @sftp . expects ( :read! ) . times ( 2 ) . returns ( "hello world" , nil )
138
+ @file . read
139
+ assert @file . eof?
140
+ @file . rewind
141
+ assert !@file . eof?
142
+ assert_equal 0 , @file . pos
143
+ end
144
+
136
145
def test_write_should_write_data_and_increment_pos_and_return_data_length
137
146
@sftp . expects ( :write! ) . with ( "handle" , 0 , "hello world" )
138
147
assert_equal 11 , @file . write ( "hello world" )
You can’t perform that action at this time.
0 commit comments