File: stat_test.rb

package info (click to toggle)
libfakefs-ruby 0.2.1-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 260 kB
  • ctags: 444
  • sloc: ruby: 1,924; makefile: 6
file content (70 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
require 'fakefs/safe'
require 'test/unit'

class FileStatTest < Test::Unit::TestCase
  include FakeFS

  def setup
    FileSystem.clear
  end

  def touch(*args)
    FileUtils.touch(*args)
  end

  def ln_s(*args)
    FileUtils.ln_s(*args)
  end

  def mkdir(*args)
    Dir.mkdir(*args)
  end

  def ln(*args)
    File.link(*args)
  end

  def test_file_stat_init_with_non_existant_file
    assert_raises(Errno::ENOENT) do
      File::Stat.new("/foo")
    end
  end

  def test_symlink_should_be_true_when_symlink
    touch("/foo")
    ln_s("/foo", "/bar")

    assert File::Stat.new("/bar").symlink?
  end

  def test_symlink_should_be_false_when_not_a_symlink
    FileUtils.touch("/foo")

    assert !File::Stat.new("/foo").symlink?
  end

  def test_should_return_false_for_directory_when_not_a_directory
    FileUtils.touch("/foo")

    assert !File::Stat.new("/foo").directory?
  end

  def test_should_return_true_for_directory_when_a_directory
    mkdir "/foo"

    assert File::Stat.new("/foo").directory?
  end

  def test_one_file_has_hard_link
    touch "testfile"
    assert_equal 1, File.stat("testfile").nlink
  end

  def test_two_hard_links_show_nlinks_as_two
    touch "testfile"
    ln    "testfile", "testfile.bak"

    assert_equal 2, File.stat("testfile").nlink
  end
end