madpilot-fakefs 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,108 @@
1
+ module FakeFS
2
+ module FileUtils
3
+ extend self
4
+
5
+ def mkdir_p(path)
6
+ FileSystem.add(path, FakeDir.new)
7
+ end
8
+
9
+ def rm(path)
10
+ FileSystem.delete(path)
11
+ end
12
+ alias_method :rm_rf, :rm
13
+ alias_method :rm_r, :rm
14
+
15
+ def ln_s(target, path)
16
+ raise Errno::EEXIST, path if FileSystem.find(path)
17
+ FileSystem.add(path, FakeSymlink.new(target))
18
+ end
19
+
20
+ def cp(src, dest)
21
+ dst_file = FileSystem.find(dest)
22
+ src_file = FileSystem.find(src)
23
+
24
+ if !src_file
25
+ raise Errno::ENOENT, src
26
+ end
27
+
28
+ if File.directory? src_file
29
+ raise Errno::EISDIR, src
30
+ end
31
+
32
+ if dst_file && File.directory?(dst_file)
33
+ FileSystem.add(File.join(dest, src), src_file.entry.clone(dst_file))
34
+ else
35
+ FileSystem.delete(dest)
36
+ FileSystem.add(dest, src_file.entry.clone)
37
+ end
38
+ end
39
+
40
+ def cp_r(src, dest)
41
+ # This error sucks, but it conforms to the original Ruby
42
+ # method.
43
+ raise "unknown file type: #{src}" unless dir = FileSystem.find(src)
44
+
45
+ new_dir = FileSystem.find(dest)
46
+
47
+ if new_dir && !File.directory?(dest)
48
+ raise Errno::EEXIST, dest
49
+ end
50
+
51
+ if !new_dir && !FileSystem.find(dest+'/../')
52
+ raise Errno::ENOENT, dest
53
+ end
54
+
55
+ # This last bit is a total abuse and should be thought hard
56
+ # about and cleaned up.
57
+ if new_dir
58
+ if src[-2..-1] == '/.'
59
+ dir.values.each{|f| new_dir[f.name] = f.clone(new_dir) }
60
+ else
61
+ new_dir[dir.name] = dir.entry.clone(new_dir)
62
+ end
63
+ else
64
+ FileSystem.add(dest, dir.entry.clone)
65
+ end
66
+ end
67
+
68
+ def mv(src, dest)
69
+ if target = FileSystem.find(src)
70
+ FileSystem.add(dest, target.entry.clone)
71
+ FileSystem.delete(src)
72
+ else
73
+ raise Errno::ENOENT, src
74
+ end
75
+ end
76
+
77
+ def chown(user, group, list, options={})
78
+ list = Array(list)
79
+ list.each do |f|
80
+ unless File.exists?(f)
81
+ raise Errno::ENOENT, f
82
+ end
83
+ end
84
+ list
85
+ end
86
+
87
+ def chown_R(user, group, list, options={})
88
+ chown(user, group, list, options={})
89
+ end
90
+
91
+ def touch(list, options={})
92
+ Array(list).each do |f|
93
+ directory = File.dirname(f)
94
+ # FIXME this explicit check for '.' shouldn't need to happen
95
+ if File.exists?(directory) || directory == '.'
96
+ FileSystem.add(f, FakeFile.new)
97
+ else
98
+ raise Errno::ENOENT, f
99
+ end
100
+ end
101
+ end
102
+
103
+ def cd(dir)
104
+ FileSystem.chdir(dir)
105
+ end
106
+ alias_method :chdir, :cd
107
+ end
108
+ end
@@ -0,0 +1,11 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+ require 'fakefs/base'
4
+ require 'fakefs/fake/file'
5
+ require 'fakefs/fake/dir'
6
+ require 'fakefs/fake/symlink'
7
+ require 'fakefs/file_system'
8
+ require 'fakefs/fileutils'
9
+ require 'fakefs/file'
10
+ require 'fakefs/dir'
11
+
@@ -0,0 +1,9 @@
1
+ module FakeFS
2
+ module Version
3
+ VERSION = "0.1.1"
4
+
5
+ def self.to_s
6
+ VERSION
7
+ end
8
+ end
9
+ end
data/lib/fakefs.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'fakefs/safe'
2
+
3
+ FakeFS.activate!