Fix that FakeFS method wouldn't call ::FakeFS.deactivate! when block raised an exception
This commit is contained in:
parent
b0830550fe
commit
7444ef50b3
@ -31,8 +31,8 @@ end
|
||||
def FakeFS
|
||||
return ::FakeFS unless block_given?
|
||||
::FakeFS.activate!
|
||||
result = yield
|
||||
::FakeFS.deactivate!
|
||||
result
|
||||
yield
|
||||
ensure
|
||||
::FakeFS.deactivate!
|
||||
end
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user