fakefs 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+ require 'fakefs/safe'
3
+ require 'test/unit'
4
+
5
+ class FileStatTest < Test::Unit::TestCase
6
+ include FakeFS
7
+
8
+ def setup
9
+ FileSystem.clear
10
+ end
11
+
12
+ def touch(*args)
13
+ FileUtils.touch(*args)
14
+ end
15
+
16
+ def ln_s(*args)
17
+ FileUtils.ln_s(*args)
18
+ end
19
+
20
+ def mkdir(*args)
21
+ Dir.mkdir(*args)
22
+ end
23
+
24
+ def ln(*args)
25
+ File.link(*args)
26
+ end
27
+
28
+ def test_file_stat_init_with_non_existant_file
29
+ assert_raises(Errno::ENOENT) do
30
+ File::Stat.new("/foo")
31
+ end
32
+ end
33
+
34
+ def test_symlink_should_be_true_when_symlink
35
+ touch("/foo")
36
+ ln_s("/foo", "/bar")
37
+
38
+ assert File::Stat.new("/bar").symlink?
39
+ end
40
+
41
+ def test_symlink_should_be_false_when_not_a_symlink
42
+ FileUtils.touch("/foo")
43
+
44
+ assert !File::Stat.new("/foo").symlink?
45
+ end
46
+
47
+ def test_should_return_false_for_directory_when_not_a_directory
48
+ FileUtils.touch("/foo")
49
+
50
+ assert !File::Stat.new("/foo").directory?
51
+ end
52
+
53
+ def test_should_return_true_for_directory_when_a_directory
54
+ mkdir "/foo"
55
+
56
+ assert File::Stat.new("/foo").directory?
57
+ end
58
+
59
+ def test_one_file_has_hard_link
60
+ touch "testfile"
61
+ assert_equal 1, File.stat("testfile").nlink
62
+ end
63
+
64
+ def test_two_hard_links_show_nlinks_as_two
65
+ touch "testfile"
66
+ ln "testfile", "testfile.bak"
67
+
68
+ assert_equal 2, File.stat("testfile").nlink
69
+ end
70
+ end
data/test/safe_test.rb CHANGED
@@ -17,4 +17,13 @@ class FakeFSSafeTest < Test::Unit::TestCase
17
17
 
18
18
  assert ! File.exists?(path)
19
19
  end
20
+
21
+ def test_FakeFS_method_returns_value_of_yield
22
+ result = FakeFS do
23
+ File.open('myfile.txt', 'w') { |f| f.write "Yatta!" }
24
+ File.read('myfile.txt')
25
+ end
26
+
27
+ assert_equal result, "Yatta!"
28
+ end
20
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakefs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-10 00:00:00 -07:00
12
+ date: 2009-10-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -37,10 +37,13 @@ files:
37
37
  - lib/fakefs/fileutils.rb
38
38
  - lib/fakefs/safe.rb
39
39
  - lib/fakefs/version.rb
40
+ - test/fake/file_test.rb
41
+ - test/fake/symlink_test.rb
40
42
  - test/fakefs_test.rb
43
+ - test/file/stat_test.rb
41
44
  - test/safe_test.rb
42
45
  - test/verify.rb
43
- has_rdoc: true
46
+ has_rdoc: false
44
47
  homepage: http://github.com/defunkt/fakefs
45
48
  licenses: []
46
49
 
@@ -69,6 +72,9 @@ signing_key:
69
72
  specification_version: 3
70
73
  summary: A fake filesystem. Use it in your tests.
71
74
  test_files:
75
+ - test/fake/file_test.rb
76
+ - test/fake/symlink_test.rb
72
77
  - test/fakefs_test.rb
78
+ - test/file/stat_test.rb
73
79
  - test/safe_test.rb
74
80
  - test/verify.rb