diff --git a/lib/fakefs/dir.rb b/lib/fakefs/dir.rb index ce97f08..a16d555 100644 --- a/lib/fakefs/dir.rb +++ b/lib/fakefs/dir.rb @@ -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 \ No newline at end of file +end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 2304a5b..e7df561 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -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 }