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
|
def FakeFS
|
||||||
return ::FakeFS unless block_given?
|
return ::FakeFS unless block_given?
|
||||||
::FakeFS.activate!
|
::FakeFS.activate!
|
||||||
result = yield
|
yield
|
||||||
::FakeFS.deactivate!
|
ensure
|
||||||
result
|
::FakeFS.deactivate!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -26,4 +26,17 @@ class FakeFSSafeTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
assert_equal result, "Yatta!"
|
assert_equal result, "Yatta!"
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user