mnoble-fakefs 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,73 @@
1
+ require "test_helper"
2
+
3
+ class FileStatTest < Test::Unit::TestCase
4
+ include FakeFS
5
+
6
+ def setup
7
+ FileSystem.clear
8
+ end
9
+
10
+ def touch(*args)
11
+ FileUtils.touch(*args)
12
+ end
13
+
14
+ def ln_s(*args)
15
+ FileUtils.ln_s(*args)
16
+ end
17
+
18
+ def mkdir(*args)
19
+ Dir.mkdir(*args)
20
+ end
21
+
22
+ def ln(*args)
23
+ File.link(*args)
24
+ end
25
+
26
+ def test_file_stat_init_with_non_existant_file
27
+ assert_raises(Errno::ENOENT) do
28
+ File::Stat.new("/foo")
29
+ end
30
+ end
31
+
32
+ def test_symlink_should_be_true_when_symlink
33
+ touch("/foo")
34
+ ln_s("/foo", "/bar")
35
+
36
+ assert File::Stat.new("/bar").symlink?
37
+ end
38
+
39
+ def test_symlink_should_be_false_when_not_a_symlink
40
+ FileUtils.touch("/foo")
41
+
42
+ assert !File::Stat.new("/foo").symlink?
43
+ end
44
+
45
+ def test_should_return_false_for_directory_when_not_a_directory
46
+ FileUtils.touch("/foo")
47
+
48
+ assert !File::Stat.new("/foo").directory?
49
+ end
50
+
51
+ def test_should_return_true_for_directory_when_a_directory
52
+ mkdir "/foo"
53
+
54
+ assert File::Stat.new("/foo").directory?
55
+ end
56
+
57
+ def test_one_file_has_hard_link
58
+ touch "testfile"
59
+ assert_equal 1, File.stat("testfile").nlink
60
+ end
61
+
62
+ def test_two_hard_links_show_nlinks_as_two
63
+ touch "testfile"
64
+ ln "testfile", "testfile.bak"
65
+
66
+ assert_equal 2, File.stat("testfile").nlink
67
+ end
68
+
69
+ def test_file_size
70
+ File.open('testfile', 'w') { |f| f << 'test' }
71
+ assert_equal 4, File.stat('testfile').size
72
+ end
73
+ end
@@ -0,0 +1,44 @@
1
+ require "test_helper"
2
+
3
+ class FakeFSSafeTest < Test::Unit::TestCase
4
+ def setup
5
+ FakeFS.deactivate!
6
+ end
7
+
8
+ def teardown
9
+ FakeFS.activate!
10
+ end
11
+
12
+ def test_FakeFS_method_does_not_intrude_on_global_namespace
13
+ path = '/path/to/file.txt'
14
+
15
+ FakeFS do
16
+ File.open(path, 'w') { |f| f.write "Yatta!" }
17
+ assert File.exists?(path)
18
+ end
19
+
20
+ assert ! File.exists?(path)
21
+ end
22
+
23
+ def test_FakeFS_method_returns_value_of_yield
24
+ result = FakeFS do
25
+ File.open('myfile.txt', 'w') { |f| f.write "Yatta!" }
26
+ File.read('myfile.txt')
27
+ end
28
+
29
+ assert_equal result, "Yatta!"
30
+ end
31
+
32
+ def test_FakeFS_method_deactivates_FakeFS_when_block_raises_exception
33
+ begin
34
+ FakeFS do
35
+ raise 'boom!'
36
+ end
37
+ rescue
38
+ end
39
+
40
+ assert_equal RealFile, File, "File is #{File} (should be #{RealFile})"
41
+ assert_equal RealFileUtils, FileUtils, "FileUtils is #{FileUtils} (should be #{RealFileUtils})"
42
+ assert_equal RealDir, Dir, "Dir is #{Dir} (should be #{RealDir})"
43
+ end
44
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'fakefs/safe'
3
+ require 'test/unit'
4
+
5
+ begin
6
+ require 'redgreen'
7
+ rescue LoadError
8
+ end
@@ -0,0 +1,31 @@
1
+ # Figure out what's missing from fakefs
2
+ #
3
+ # USAGE
4
+ #
5
+ # $ RUBYLIB=test ruby test/verify.rb | grep "not implemented"
6
+
7
+ require "test_helper"
8
+
9
+ class FakeFSVerifierTest < Test::Unit::TestCase
10
+ class_mapping = {
11
+ RealFile => FakeFS::File,
12
+ RealFile::Stat => FakeFS::File::Stat,
13
+ RealFileUtils => FakeFS::FileUtils,
14
+ RealDir => FakeFS::Dir,
15
+ RealFileTest => FakeFS::FileTest
16
+ }
17
+
18
+ class_mapping.each do |real_class, fake_class|
19
+ real_class.methods.each do |method|
20
+ define_method "test #{method} class method" do
21
+ assert fake_class.respond_to?(method), "#{fake_class}.#{method} not implemented"
22
+ end
23
+ end
24
+
25
+ real_class.instance_methods.each do |method|
26
+ define_method("test #{method} instance method") do
27
+ assert fake_class.instance_methods.include?(method), "#{fake_class}##{name} not implemented"
28
+ end
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mnoble-fakefs
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.3.1
6
+ platform: ruby
7
+ authors:
8
+ - Chris Wanstrath
9
+ - Scott Taylor
10
+ - Jeff Hodges
11
+ - Pat Nakajima
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-12-18 00:00:00 -05:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: A fake filesystem. Use it in your tests. (Updates to support mkdir)
21
+ email: chris@ozmm.org
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files:
27
+ - LICENSE
28
+ - README.markdown
29
+ files:
30
+ - .autotest
31
+ - .gitignore
32
+ - CONTRIBUTORS
33
+ - LICENSE
34
+ - README.markdown
35
+ - Rakefile
36
+ - fakefs.gemspec
37
+ - lib/fakefs.rb
38
+ - lib/fakefs/base.rb
39
+ - lib/fakefs/dir.rb
40
+ - lib/fakefs/fake/dir.rb
41
+ - lib/fakefs/fake/file.rb
42
+ - lib/fakefs/fake/symlink.rb
43
+ - lib/fakefs/file.rb
44
+ - lib/fakefs/file_system.rb
45
+ - lib/fakefs/file_test.rb
46
+ - lib/fakefs/fileutils.rb
47
+ - lib/fakefs/safe.rb
48
+ - lib/fakefs/spec_helpers.rb
49
+ - lib/fakefs/version.rb
50
+ - spec/fakefs/spec_helpers_spec.rb
51
+ - spec/spec.opts
52
+ - spec/spec_helper.rb
53
+ - test/fake/file/lstat_test.rb
54
+ - test/fake/file/stat_test.rb
55
+ - test/fake/file/sysseek_test.rb
56
+ - test/fake/file/syswrite_test.rb
57
+ - test/fake/file_test.rb
58
+ - test/fake/symlink_test.rb
59
+ - test/fakefs_test.rb
60
+ - test/file/stat_test.rb
61
+ - test/safe_test.rb
62
+ - test/test_helper.rb
63
+ - test/verify.rb
64
+ has_rdoc: true
65
+ homepage: http://github.com/defunkt/fakefs
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --charset=UTF-8
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.5.2
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: A fake filesystem. Use it in your tests.
92
+ test_files:
93
+ - spec/fakefs/spec_helpers_spec.rb
94
+ - spec/spec_helper.rb
95
+ - test/fake/file/lstat_test.rb
96
+ - test/fake/file/stat_test.rb
97
+ - test/fake/file/sysseek_test.rb
98
+ - test/fake/file/syswrite_test.rb
99
+ - test/fake/file_test.rb
100
+ - test/fake/symlink_test.rb
101
+ - test/fakefs_test.rb
102
+ - test/file/stat_test.rb
103
+ - test/safe_test.rb
104
+ - test/test_helper.rb
105
+ - test/verify.rb