few more read tests, readlines

This commit is contained in:
Chris Wanstrath 2009-05-29 11:46:49 -07:00
parent 33e176a353
commit b9a8f4e8ca
2 changed files with 23 additions and 0 deletions

View File

@ -87,6 +87,10 @@ module FakeFS
new(path).read new(path).read
end end
def self.readlines(path)
read(path).split("\n")
end
attr_reader :path attr_reader :path
def initialize(path, mode = nil) def initialize(path, mode = nil)
@path = path @path = path

View File

@ -79,6 +79,25 @@ class FakeFSTest < Test::Unit::TestCase
assert_equal "Yatta!", File.read(path) assert_equal "Yatta!", File.read(path)
end 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 def test_knows_files_are_files
path = '/path/to/file.txt' path = '/path/to/file.txt'
File.open(path, 'w') do |f| File.open(path, 'w') do |f|