From 9e50475cb3b86e71fd04a0e08c4818f385f10426 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sun, 1 Nov 2009 17:44:30 -0500 Subject: [PATCH] Add File#pos --- lib/fakefs/file.rb | 4 ++++ test/fakefs_test.rb | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/fakefs/file.rb b/lib/fakefs/file.rb index 4b1099f..7479f2c 100644 --- a/lib/fakefs/file.rb +++ b/lib/fakefs/file.rb @@ -249,6 +249,10 @@ module FakeFS @stream.seek(amount, whence) end + def pos + @stream.pos + end + private def check_modes! diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index af6aa93..806a849 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -445,6 +445,26 @@ class FakeFSTest < Test::Unit::TestCase assert_equal ['/one/five.rb', '/one/two/three/four.rb'], Dir['/one/**'] end + def test_should_report_pos_as_0_when_opening + File.open("/foo", "w") do |f| + f << "foobar" + f.rewind + + assert_equal 0, f.pos + end + end + + def test_should_report_pos_as_1_when_seeking_one_char + File.open("/foo", "w") do |f| + f << "foobar" + + f.rewind + f.seek(1) + + assert_equal 1, f.pos + end + end + def test_chdir_changes_directories_like_a_boss # I know memes! FileUtils.mkdir_p '/path'