From 35c88244def6e3c1903b440db88cedc94d1472c4 Mon Sep 17 00:00:00 2001 From: Jeff Hodges Date: Sat, 30 May 2009 11:31:19 -0700 Subject: [PATCH] default File.open to read mode --- lib/fakefs.rb | 2 +- test/fakefs_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fakefs.rb b/lib/fakefs.rb index 1792768..07a937d 100644 --- a/lib/fakefs.rb +++ b/lib/fakefs.rb @@ -89,7 +89,7 @@ module FakeFS FileSystem.find(symlink.target).to_s end - def self.open(path, mode) + def self.open(path, mode='r') if block_given? yield new(path, mode) else diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index af134bf..a8c0d36 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -188,4 +188,9 @@ class FakeFSTest < Test::Unit::TestCase assert_equal(['foo', 'foobar'], FileSystem.fs['path'].keys.sort) end + + def test_file_open_defaults_to_read + File.open('foo','w'){|f| f.write 'bar' } + assert_equal 'bar', File.open('foo'){|f| f.read } + end end