Skip to content
This repository
Browse code

Add File::Stat#ftype

  • Loading branch information...
commit 89a7e39425f1ebdddcb2ebffbbc4227a99cd05cb 1 parent 690c1ad
Matt Rogers mattr- authored smtlaissezfaire committed

Showing 2 changed files with 10 additions and 0 deletions. Show diff stats Hide diff stats

  1. +6 0 lib/fakefs/file.rb
  2. +4 0 test/file/stat_test.rb
6 lib/fakefs/file.rb
@@ -289,6 +289,12 @@ def directory?
289 289 File.directory?(@file)
290 290 end
291 291
  292 + def ftype
  293 + return 'link' if symlink?
  294 + return 'directory' if directory?
  295 + return 'file'
  296 + end
  297 +
292 298 # assumes, like above, that all files are readable and writable
293 299 def readable?
294 300 true
4 test/file/stat_test.rb
@@ -34,24 +34,28 @@ def test_symlink_should_be_true_when_symlink
34 34 ln_s("/foo", "/bar")
35 35
36 36 assert File::Stat.new("/bar").symlink?
  37 + assert File::Stat.new("/bar").ftype == "link"
37 38 end
38 39
39 40 def test_symlink_should_be_false_when_not_a_symlink
40 41 FileUtils.touch("/foo")
41 42
42 43 assert !File::Stat.new("/foo").symlink?
  44 + assert File::Stat.new("/foo").ftype == "file"
43 45 end
44 46
45 47 def test_should_return_false_for_directory_when_not_a_directory
46 48 FileUtils.touch("/foo")
47 49
48 50 assert !File::Stat.new("/foo").directory?
  51 + assert File::Stat.new("/foo").ftype == "file"
49 52 end
50 53
51 54 def test_should_return_true_for_directory_when_a_directory
52 55 mkdir "/foo"
53 56
54 57 assert File::Stat.new("/foo").directory?
  58 + assert File::Stat.new("/foo").ftype == "directory"
55 59 end
56 60
57 61 def test_writable_is_true

0 comments on commit 89a7e39

Please sign in to comment.
Something went wrong with that request. Please try again.