Fix that FakeFS method wouldn't call ::FakeFS.deactivate! when block raised an exception

This commit is contained in:
jameswilding 2009-10-19 19:38:59 +08:00 committed by Pat Nakajima
parent b0830550fe
commit 7444ef50b3
2 changed files with 16 additions and 3 deletions

View File

@ -31,8 +31,8 @@ end
def FakeFS
return ::FakeFS unless block_given?
::FakeFS.activate!
result = yield
::FakeFS.deactivate!
result
yield
ensure
::FakeFS.deactivate!
end

View File

@ -26,4 +26,17 @@ class FakeFSSafeTest < Test::Unit::TestCase
assert_equal result, "Yatta!"
end
def test_FakeFS_method_deactivates_FakeFS_when_block_raises_exception
begin
FakeFS do
raise 'boom!'
end
rescue
end
assert_equal RealFile, File, "File is #{File} (should be #{RealFile})"
assert_equal RealFileUtils, FileUtils, "FileUtils is #{FileUtils} (should be #{RealFileUtils})"
assert_equal RealDir, Dir, "Dir is #{Dir} (should be #{RealDir})"
end
end