Dir.pwd and Dir.getwd

This commit is contained in:
Matt Freels 2009-07-27 10:56:56 -07:00
parent 9fb29f122d
commit 506a33fed4
2 changed files with 23 additions and 1 deletions

View File

@ -16,5 +16,13 @@ module FakeFS
def self.chdir(dir, &blk)
FileSystem.chdir(dir, &blk)
end
def self.pwd
FileSystem.current_dir.to_s
end
class << self
alias_method :getwd, :pwd
end
end
end

View File

@ -312,6 +312,20 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal ['foo'], FileSystem.current_dir.keys
end
def test_current_dir_reflected_by_pwd
FileUtils.mkdir_p '/path'
Dir.chdir('/path')
assert_equal '/path', Dir.pwd
assert_equal '/path', Dir.getwd
FileUtils.mkdir_p 'subdir'
Dir.chdir('subdir')
assert_equal '/path/subdir', Dir.pwd
assert_equal '/path/subdir', Dir.getwd
end
def test_file_open_defaults_to_read
File.open('foo','w'){|f| f.write 'bar' }
assert_equal 'bar', File.open('foo'){|f| f.read }