Permalink
Browse files

Add File.utime for updating files' mtime. Closes #28

Conflicts:

	lib/fakefs/file.rb
	test/fakefs_test.rb
  • Loading branch information...
smtlaissezfaire committed Dec 27, 2010
1 parent b6e5d10 commit d422c6a79fa486e4cf3e46aa01a1ffff8a919a0e
Showing with 40 additions and 2 deletions.
  1. +2 −2 lib/fakefs/fake/file.rb
  2. +12 −0 lib/fakefs/file.rb
  3. +26 −0 test/fakefs_test.rb
View
@@ -1,7 +1,7 @@
module FakeFS
class FakeFile
attr_accessor :name, :parent, :content
attr_reader :ctime, :mtime
attr_accessor :name, :parent, :content, :mtime
attr_reader :ctime
class Inode
def initialize(file_owner)
View
@@ -64,6 +64,18 @@ def self.ctime(path)
end
end
def self.utime(atime, mtime, *paths)
paths.each do |path|
if exists?(path)
FileSystem.find(path).mtime = mtime
else
raise Errno::ENOENT
end
end
paths.size
end
def self.size(path)
read(path).length
end
View
@@ -384,6 +384,32 @@ def test_directory_mtime_is_equal_to_directory_stat_mtime
assert_equal File.stat("foo").mtime, File.mtime("foo")
end
def test_utime_raises_error_if_path_does_not_exist
assert_raise Errno::ENOENT do
File.utime(Time.now, Time.now, '/path/to/file.txt')
end
end
def test_can_call_utime_on_an_existing_file
time = Time.now - 300 # Not now
path = '/path/to/file.txt'
File.open(path, 'w') do |f|
f << ''
end
File.utime(time, time, path)
assert_equal time, File.mtime('/path/to/file.txt')
end
def test_utime_returns_number_of_paths
path1, path2 = '/path/to/file.txt', '/path/to/another_file.txt'
[path1, path2].each do |path|
File.open(path, 'w') do |f|
f << ''
end
end
assert_equal 2, File.utime(Time.now, Time.now, path1, path2)
end
def test_can_read_with_File_readlines
path = '/path/to/file.txt'
File.open(path, 'w') do |f|

0 comments on commit d422c6a

Please sign in to comment.