Return result of yield from FakeFS block
Signed-off-by: Chris Wanstrath <chris@ozmm.org>
This commit is contained in:
parent
25e47887b0
commit
0da41d92a7
@ -31,7 +31,8 @@ end
|
|||||||
def FakeFS
|
def FakeFS
|
||||||
return ::FakeFS unless block_given?
|
return ::FakeFS unless block_given?
|
||||||
::FakeFS.activate!
|
::FakeFS.activate!
|
||||||
yield
|
result = yield
|
||||||
::FakeFS.deactivate!
|
::FakeFS.deactivate!
|
||||||
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,4 +17,13 @@ class FakeFSSafeTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
assert ! File.exists?(path)
|
assert ! File.exists?(path)
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user