diff --git a/lib/fakefs/file_test.rb b/lib/fakefs/file_test.rb index 5dbdbf5..2f6a61d 100644 --- a/lib/fakefs/file_test.rb +++ b/lib/fakefs/file_test.rb @@ -7,5 +7,9 @@ module FakeFS def self.directory?(file_name) File.directory?(file_name) end + + def self.file?(file_name) + File.file?(file_name) + end end end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index e75aaf4..cc0041c 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -1584,6 +1584,18 @@ class FakeFSTest < Test::Unit::TestCase assert !FileTest.directory?('/path/to/somedir') end + def test_filetest_file_returns_correct_values + path = '/path/to/file.txt' + File.open(path, 'w') { |f| f.write "Yatta!" } + assert FileTest.file?(path) + + FileUtils.rm path + assert !FileTest.file?(path) + + FileUtils.mkdir_p '/path/to/somedir' + assert !FileTest.file?('/path/to/somedir') + end + def test_pathname_exists_returns_correct_value FileUtils.touch "foo" assert Pathname.new("foo").exist?