From b9a8f4e8ca43d2dc48eea3c20915f6da842e2bbd Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Fri, 29 May 2009 11:46:49 -0700 Subject: [PATCH] few more read tests, readlines --- lib/fakefs.rb | 4 ++++ test/fakefs_test.rb | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/fakefs.rb b/lib/fakefs.rb index b80ec78..68e9f7a 100644 --- a/lib/fakefs.rb +++ b/lib/fakefs.rb @@ -87,6 +87,10 @@ module FakeFS new(path).read end + def self.readlines(path) + read(path).split("\n") + end + attr_reader :path def initialize(path, mode = nil) @path = path diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index 83b6b78..8f64ebc 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -79,6 +79,25 @@ class FakeFSTest < Test::Unit::TestCase assert_equal "Yatta!", File.read(path) end + def test_can_read_with_File_readlines + path = '/path/to/file.txt' + File.open(path, 'w') do |f| + f.puts "Yatta!" + f.puts "woot" + end + + assert_equal ["Yatta!", "woot"], File.readlines(path) + end + + def test_can_read_from_file_objects + path = '/path/to/file.txt' + File.open(path, 'w') do |f| + f.write "Yatta!" + end + + assert_equal "Yatta!", File.new(path).read + end + def test_knows_files_are_files path = '/path/to/file.txt' File.open(path, 'w') do |f|