Return result of yield from FakeFS block

Signed-off-by: Chris Wanstrath <chris@ozmm.org>
This commit is contained in:
msassak 2009-09-22 13:26:11 +08:00 committed by Chris Wanstrath
parent 25e47887b0
commit 0da41d92a7
2 changed files with 11 additions and 1 deletions

View File

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

View File

@ -17,4 +17,13 @@ class FakeFSSafeTest < Test::Unit::TestCase
assert ! File.exists?(path)
end
def test_FakeFS_method_returns_value_of_yield
result = FakeFS do
File.open('myfile.txt', 'w') { |f| f.write "Yatta!" }
File.read('myfile.txt')
end
assert_equal result, "Yatta!"
end
end