1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
# frozen_string_literal: true
require_relative '../../test_helper'
# File stat test class
class FakeFileStatTest < Minitest::Test
def setup
FakeFS.activate!
FakeFS::FileSystem.clear
end
def teardown
FakeFS.deactivate!
FakeFS::FileSystem.clear
end
def test_calling_stat_should_create_a_new_file_stat_object
File.open('foo', 'w') do |f|
f << 'bar'
end
File.open('foo') do |f|
assert_equal File::Stat, f.stat.class
end
end
def test_stat_should_use_correct_file
File.open('bar', 'w') do |f|
f << '1'
end
File.open('bar') do |f|
assert_equal 1, f.stat.size
end
end
def test_stat_should_report_on_symlink_pointer
File.open('foo', 'w') { |f| f << 'some content' }
File.symlink 'foo', 'my_symlink'
assert_equal File.stat('my_symlink').size, File.stat('foo').size
end
def test_stat_should_report_on_symlink_pointer_in_subdirectory
Dir.mkdir('tmp')
Dir.chdir('tmp') do
File.open('foo', 'w') { |f| f << 'some content' }
File.symlink 'foo', 'my_symlink'
assert_equal File.stat('my_symlink').size, File.stat('foo').size
end
assert_equal File.stat('tmp/my_symlink').size, File.stat('tmp/foo').size
end
end
|