Permalink
Browse files

Add File::Stat#ftype

  • Loading branch information...
1 parent 690c1ad commit 89a7e39425f1ebdddcb2ebffbbc4227a99cd05cb @mattr- mattr- committed with smtlaissezfaire Dec 31, 2012
Showing with 10 additions and 0 deletions.
  1. +6 −0 lib/fakefs/file.rb
  2. +4 −0 test/file/stat_test.rb
View
@@ -289,6 +289,12 @@ def directory?
File.directory?(@file)
end
+ def ftype
+ return 'link' if symlink?
+ return 'directory' if directory?
+ return 'file'
+ end
+
# assumes, like above, that all files are readable and writable
def readable?
true
@@ -34,24 +34,28 @@ def test_symlink_should_be_true_when_symlink
ln_s("/foo", "/bar")
assert File::Stat.new("/bar").symlink?
+ assert File::Stat.new("/bar").ftype == "link"
end
def test_symlink_should_be_false_when_not_a_symlink
FileUtils.touch("/foo")
assert !File::Stat.new("/foo").symlink?
+ assert File::Stat.new("/foo").ftype == "file"
end
def test_should_return_false_for_directory_when_not_a_directory
FileUtils.touch("/foo")
assert !File::Stat.new("/foo").directory?
+ assert File::Stat.new("/foo").ftype == "file"
end
def test_should_return_true_for_directory_when_a_directory
mkdir "/foo"
assert File::Stat.new("/foo").directory?
+ assert File::Stat.new("/foo").ftype == "directory"
end
def test_writable_is_true

0 comments on commit 89a7e39

Please sign in to comment.