File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -131,11 +131,14 @@ def print(*items)
131
131
nil
132
132
end
133
133
134
- # Returns the size of the file from stats
135
134
def size
136
135
stat . size
137
136
end
138
137
138
+ def rewind
139
+ self . pos = 0
140
+ end
141
+
139
142
# Writes each argument to the stream, appending a newline to any item
140
143
# that does not already end in a newline. Array arguments are flattened.
141
144
def puts ( *items )
Original file line number Diff line number Diff line change @@ -162,4 +162,14 @@ def test_size_should_return_size_from_stat
162
162
@sftp . expects ( :fstat! ) . with ( "handle" ) . returns ( stat )
163
163
assert_equal 1024 , @file . size
164
164
end
165
+
166
+ def test_rewind
167
+ @sftp . expects ( :write! ) . with ( "handle" , 0 , "hello world\n " )
168
+ @sftp . expects ( :read! ) . with ( "handle" , 12 , 8192 ) . returns ( "hello world\n " )
169
+ @sftp . expects ( :read! ) . with ( "handle" , 0 , 8192 ) . returns ( "hello world\n " )
170
+ @file . puts "hello world\n "
171
+ assert_equal "hello" , @file . read ( 5 )
172
+ @file . rewind
173
+ assert_equal "hello world" , @file . read ( 11 )
174
+ end
165
175
end
You can’t perform that action at this time.
0 commit comments