diff --git a/lib/fakefs/base.rb b/lib/fakefs/base.rb index 09bf720..5c54fb9 100644 --- a/lib/fakefs/base.rb +++ b/lib/fakefs/base.rb @@ -31,7 +31,8 @@ end def FakeFS return ::FakeFS unless block_given? ::FakeFS.activate! - yield + result = yield ::FakeFS.deactivate! + result end diff --git a/test/safe_test.rb b/test/safe_test.rb index ac0f63f..5916d69 100644 --- a/test/safe_test.rb +++ b/test/safe_test.rb @@ -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