fakefs 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +5 -0
- data/.gitignore +2 -0
- data/CONTRIBUTORS +12 -3
- data/README.markdown +29 -7
- data/Rakefile +22 -8
- data/fakefs.gemspec +86 -0
- data/lib/fakefs/base.rb +16 -9
- data/lib/fakefs/dir.rb +1 -0
- data/lib/fakefs/fake/dir.rb +4 -1
- data/lib/fakefs/fake/file.rb +4 -2
- data/lib/fakefs/fake/symlink.rb +1 -1
- data/lib/fakefs/file.rb +125 -31
- data/lib/fakefs/file_system.rb +5 -2
- data/lib/fakefs/file_test.rb +7 -0
- data/lib/fakefs/fileutils.rb +6 -6
- data/lib/fakefs/safe.rb +1 -1
- data/lib/fakefs/version.rb +1 -1
- data/spec/fakefs/spec_helpers_spec.rb +1 -1
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +1 -1
- data/test/fake/file/lstat_test.rb +59 -0
- data/test/fake/file/stat_test.rb +39 -0
- data/test/fake/file/sysseek_test.rb +44 -0
- data/test/fake/file/syswrite_test.rb +62 -0
- data/test/fake/file_test.rb +4 -6
- data/test/fake/symlink_test.rb +1 -3
- data/test/fakefs_test.rb +259 -22
- data/test/file/stat_test.rb +6 -3
- data/test/safe_test.rb +9 -7
- data/test/test_helper.rb +8 -0
- data/test/verify.rb +22 -18
- metadata +34 -6
data/.autotest
ADDED
data/.gitignore
CHANGED
data/CONTRIBUTORS
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
* Chris Wanstrath
|
2
|
-
* Jeff Hodges
|
3
2
|
* Scott Taylor
|
3
|
+
* Jeff Hodges
|
4
4
|
* Pat Nakajima
|
5
5
|
* Myles Eftos
|
6
6
|
* Matt Freels
|
7
7
|
* Nick Quaranto
|
8
8
|
* Tymon Tobolski
|
9
|
-
*
|
10
|
-
* Rob Sanheim
|
9
|
+
* Ben Mabey
|
11
10
|
* Jon Yurek
|
11
|
+
* Scott Barron
|
12
|
+
* dmathieu
|
13
|
+
* Rob Sanheim
|
12
14
|
* David Reese
|
15
|
+
* msassak
|
16
|
+
* Sam Goldstein
|
17
|
+
* jameswilding
|
18
|
+
* Greg Campbell
|
19
|
+
* Thiago Marano
|
20
|
+
* Víctor Martínez
|
21
|
+
* Victor Costan
|
data/README.markdown
CHANGED
@@ -37,11 +37,11 @@ Don't Fake the FS Immediately
|
|
37
37
|
-----------------------------
|
38
38
|
|
39
39
|
require 'fakefs/safe'
|
40
|
-
|
40
|
+
|
41
41
|
FakeFS.activate!
|
42
42
|
# your code
|
43
43
|
FakeFS.deactivate!
|
44
|
-
|
44
|
+
|
45
45
|
# or
|
46
46
|
FakeFS do
|
47
47
|
# your code
|
@@ -49,10 +49,18 @@ Don't Fake the FS Immediately
|
|
49
49
|
|
50
50
|
|
51
51
|
RSpec
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
-----
|
53
|
+
|
54
|
+
The above approach works with RSpec as well. In addition you may include
|
55
|
+
FakeFS::SpecHelpers to turn FakeFS on and off in a given example group:
|
56
|
+
|
57
|
+
require 'fakefs/spec_helpers'
|
58
|
+
|
59
|
+
describe "my spec" do
|
60
|
+
include FakeFS::SpecHelpers
|
61
|
+
end
|
62
|
+
|
63
|
+
See `lib/fakefs/spec_helpers.rb` for more info.
|
56
64
|
|
57
65
|
|
58
66
|
How is this different than MockFS?
|
@@ -73,6 +81,7 @@ on FakeFS' own require.
|
|
73
81
|
|
74
82
|
Speed?
|
75
83
|
------
|
84
|
+
|
76
85
|
<http://gist.github.com/156091>
|
77
86
|
|
78
87
|
|
@@ -88,6 +97,17 @@ Installation
|
|
88
97
|
$ rip install git://github.com/defunkt/fakefs.git
|
89
98
|
|
90
99
|
|
100
|
+
Contributing
|
101
|
+
------------
|
102
|
+
|
103
|
+
Once you've made your great commits:
|
104
|
+
|
105
|
+
1. [Fork][0] FakeFS
|
106
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
107
|
+
3. Push to your branch - `git push origin my_branch`
|
108
|
+
4. Create an [Issue][1] with a link to your branch
|
109
|
+
5. That's it!
|
110
|
+
|
91
111
|
Meta
|
92
112
|
----
|
93
113
|
|
@@ -98,4 +118,6 @@ Meta
|
|
98
118
|
* List: <http://groups.google.com/group/fakefs>
|
99
119
|
* Test: <http://runcoderun.com/defunkt/fakefs>
|
100
120
|
* Gems: <http://gemcutter.org/gems/fakefs>
|
101
|
-
|
121
|
+
|
122
|
+
[0]: http://help.github.com/forking/
|
123
|
+
[1]: http://github.com/defunkt/fakefs/issues
|
data/Rakefile
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'test')
|
3
|
+
|
1
4
|
desc "Run tests"
|
2
5
|
task :test do
|
3
6
|
Dir['test/**/*_test.rb'].each { |file| require file }
|
4
7
|
end
|
5
8
|
|
6
|
-
task :default => :test
|
9
|
+
task :default => [:test, :spec]
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'spec/rake/spectask'
|
13
|
+
|
14
|
+
desc "Run specs"
|
15
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
16
|
+
t.spec_files = FileList["spec/**/*.rb"]
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Spec task can't be loaded. `gem install rspec`"
|
20
|
+
end
|
7
21
|
|
8
22
|
begin
|
9
23
|
require 'jeweler'
|
@@ -12,14 +26,14 @@ begin
|
|
12
26
|
require 'fakefs/version'
|
13
27
|
|
14
28
|
Jeweler::Tasks.new do |gemspec|
|
15
|
-
gemspec.name
|
16
|
-
gemspec.summary
|
17
|
-
gemspec.email
|
18
|
-
gemspec.homepage
|
29
|
+
gemspec.name = "fakefs"
|
30
|
+
gemspec.summary = "A fake filesystem. Use it in your tests."
|
31
|
+
gemspec.email = "chris@ozmm.org"
|
32
|
+
gemspec.homepage = "http://github.com/defunkt/fakefs"
|
19
33
|
gemspec.description = "A fake filesystem. Use it in your tests."
|
20
|
-
gemspec.authors
|
21
|
-
gemspec.has_rdoc
|
22
|
-
gemspec.version
|
34
|
+
gemspec.authors = ["Chris Wanstrath", "Scott Taylor", "Jeff Hodges", "Pat Nakajima"]
|
35
|
+
gemspec.has_rdoc = false
|
36
|
+
gemspec.version = FakeFS::Version.to_s
|
23
37
|
end
|
24
38
|
rescue LoadError
|
25
39
|
puts "Jeweler not available."
|
data/fakefs.gemspec
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{fakefs}
|
8
|
+
s.version = "0.3.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Chris Wanstrath", "Scott Taylor", "Jeff Hodges", "Pat Nakajima"]
|
12
|
+
s.date = %q{2010-12-18}
|
13
|
+
s.description = %q{A fake filesystem. Use it in your tests.}
|
14
|
+
s.email = %q{chris@ozmm.org}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".autotest",
|
21
|
+
".gitignore",
|
22
|
+
"CONTRIBUTORS",
|
23
|
+
"LICENSE",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"fakefs.gemspec",
|
27
|
+
"lib/fakefs.rb",
|
28
|
+
"lib/fakefs/base.rb",
|
29
|
+
"lib/fakefs/dir.rb",
|
30
|
+
"lib/fakefs/fake/dir.rb",
|
31
|
+
"lib/fakefs/fake/file.rb",
|
32
|
+
"lib/fakefs/fake/symlink.rb",
|
33
|
+
"lib/fakefs/file.rb",
|
34
|
+
"lib/fakefs/file_system.rb",
|
35
|
+
"lib/fakefs/file_test.rb",
|
36
|
+
"lib/fakefs/fileutils.rb",
|
37
|
+
"lib/fakefs/safe.rb",
|
38
|
+
"lib/fakefs/spec_helpers.rb",
|
39
|
+
"lib/fakefs/version.rb",
|
40
|
+
"spec/fakefs/spec_helpers_spec.rb",
|
41
|
+
"spec/spec.opts",
|
42
|
+
"spec/spec_helper.rb",
|
43
|
+
"test/fake/file/lstat_test.rb",
|
44
|
+
"test/fake/file/stat_test.rb",
|
45
|
+
"test/fake/file/sysseek_test.rb",
|
46
|
+
"test/fake/file/syswrite_test.rb",
|
47
|
+
"test/fake/file_test.rb",
|
48
|
+
"test/fake/symlink_test.rb",
|
49
|
+
"test/fakefs_test.rb",
|
50
|
+
"test/file/stat_test.rb",
|
51
|
+
"test/safe_test.rb",
|
52
|
+
"test/test_helper.rb",
|
53
|
+
"test/verify.rb"
|
54
|
+
]
|
55
|
+
s.homepage = %q{http://github.com/defunkt/fakefs}
|
56
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
57
|
+
s.require_paths = ["lib"]
|
58
|
+
s.rubygems_version = %q{1.3.7}
|
59
|
+
s.summary = %q{A fake filesystem. Use it in your tests.}
|
60
|
+
s.test_files = [
|
61
|
+
"spec/fakefs/spec_helpers_spec.rb",
|
62
|
+
"spec/spec_helper.rb",
|
63
|
+
"test/fake/file/lstat_test.rb",
|
64
|
+
"test/fake/file/stat_test.rb",
|
65
|
+
"test/fake/file/sysseek_test.rb",
|
66
|
+
"test/fake/file/syswrite_test.rb",
|
67
|
+
"test/fake/file_test.rb",
|
68
|
+
"test/fake/symlink_test.rb",
|
69
|
+
"test/fakefs_test.rb",
|
70
|
+
"test/file/stat_test.rb",
|
71
|
+
"test/safe_test.rb",
|
72
|
+
"test/test_helper.rb",
|
73
|
+
"test/verify.rb"
|
74
|
+
]
|
75
|
+
|
76
|
+
if s.respond_to? :specification_version then
|
77
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
78
|
+
s.specification_version = 3
|
79
|
+
|
80
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
81
|
+
else
|
82
|
+
end
|
83
|
+
else
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
data/lib/fakefs/base.rb
CHANGED
@@ -1,30 +1,37 @@
|
|
1
|
-
RealFile
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
RealFileUtils::File = RealFile
|
1
|
+
RealFile = File
|
2
|
+
RealFileTest = FileTest
|
3
|
+
RealFileUtils = FileUtils
|
4
|
+
RealDir = Dir
|
6
5
|
|
7
6
|
module FakeFS
|
8
7
|
def self.activate!
|
9
8
|
Object.class_eval do
|
10
9
|
remove_const(:Dir)
|
11
10
|
remove_const(:File)
|
11
|
+
remove_const(:FileTest)
|
12
12
|
remove_const(:FileUtils)
|
13
|
-
|
14
|
-
const_set(:
|
13
|
+
|
14
|
+
const_set(:Dir, FakeFS::Dir)
|
15
|
+
const_set(:File, FakeFS::File)
|
15
16
|
const_set(:FileUtils, FakeFS::FileUtils)
|
17
|
+
const_set(:FileTest, FakeFS::FileTest)
|
16
18
|
end
|
19
|
+
true
|
17
20
|
end
|
18
21
|
|
19
22
|
def self.deactivate!
|
20
23
|
Object.class_eval do
|
21
24
|
remove_const(:Dir)
|
22
25
|
remove_const(:File)
|
26
|
+
remove_const(:FileTest)
|
23
27
|
remove_const(:FileUtils)
|
24
|
-
|
25
|
-
const_set(:
|
28
|
+
|
29
|
+
const_set(:Dir, RealDir)
|
30
|
+
const_set(:File, RealFile)
|
31
|
+
const_set(:FileTest, RealFileTest)
|
26
32
|
const_set(:FileUtils, RealFileUtils)
|
27
33
|
end
|
34
|
+
true
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
data/lib/fakefs/dir.rb
CHANGED
@@ -86,6 +86,7 @@ module FakeFS
|
|
86
86
|
parent = string.split('/')
|
87
87
|
parent.pop
|
88
88
|
raise Errno::ENOENT, "No such file or directory - #{string}" unless parent.join == "" || FileSystem.find(parent.join('/'))
|
89
|
+
raise Errno::EEXIST, "File exists - #{string}" if File.exists?(string)
|
89
90
|
FileUtils.mkdir_p(string)
|
90
91
|
end
|
91
92
|
|
data/lib/fakefs/fake/dir.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
module FakeFS
|
2
2
|
class FakeDir < Hash
|
3
3
|
attr_accessor :name, :parent
|
4
|
+
attr_reader :ctime, :mtime
|
4
5
|
|
5
6
|
def initialize(name = nil, parent = nil)
|
6
|
-
@name
|
7
|
+
@name = name
|
7
8
|
@parent = parent
|
9
|
+
@ctime = Time.now
|
10
|
+
@mtime = @ctime
|
8
11
|
end
|
9
12
|
|
10
13
|
def entry
|
data/lib/fakefs/fake/file.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module FakeFS
|
2
2
|
class FakeFile
|
3
|
-
attr_accessor :name, :parent, :content
|
3
|
+
attr_accessor :name, :parent, :content
|
4
|
+
attr_reader :ctime, :mtime
|
4
5
|
|
5
6
|
class Inode
|
6
7
|
def initialize(file_owner)
|
@@ -31,7 +32,8 @@ module FakeFS
|
|
31
32
|
@name = name
|
32
33
|
@parent = parent
|
33
34
|
@inode = Inode.new(self)
|
34
|
-
@
|
35
|
+
@ctime = Time.now
|
36
|
+
@mtime = @ctime
|
35
37
|
end
|
36
38
|
|
37
39
|
attr_accessor :inode
|
data/lib/fakefs/fake/symlink.rb
CHANGED
data/lib/fakefs/file.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
1
3
|
module FakeFS
|
2
|
-
class File
|
4
|
+
class File < StringIO
|
3
5
|
PATH_SEPARATOR = '/'
|
4
6
|
|
5
7
|
MODES = [
|
@@ -54,6 +56,14 @@ module FakeFS
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
59
|
+
def self.ctime(path)
|
60
|
+
if exists?(path)
|
61
|
+
FileSystem.find(path).ctime
|
62
|
+
else
|
63
|
+
raise Errno::ENOENT
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
57
67
|
def self.size(path)
|
58
68
|
read(path).length
|
59
69
|
end
|
@@ -113,14 +123,6 @@ module FakeFS
|
|
113
123
|
FileSystem.find(symlink.target).to_s
|
114
124
|
end
|
115
125
|
|
116
|
-
def self.open(path, mode=READ_ONLY, perm = 0644)
|
117
|
-
if block_given?
|
118
|
-
yield new(path, mode, perm)
|
119
|
-
else
|
120
|
-
new(path, mode, perm)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
126
|
def self.read(path)
|
125
127
|
file = new(path)
|
126
128
|
if file.exists?
|
@@ -180,13 +182,23 @@ module FakeFS
|
|
180
182
|
File::Stat.new(file)
|
181
183
|
end
|
182
184
|
|
185
|
+
def self.lstat(file)
|
186
|
+
File::Stat.new(file, true)
|
187
|
+
end
|
188
|
+
|
183
189
|
class Stat
|
184
|
-
|
190
|
+
attr_reader :ctime, :mtime
|
191
|
+
|
192
|
+
def initialize(file, __lstat = false)
|
185
193
|
if !File.exists?(file)
|
186
194
|
raise(Errno::ENOENT, "No such file or directory - #{file}")
|
187
195
|
end
|
188
196
|
|
189
|
-
@file
|
197
|
+
@file = file
|
198
|
+
@fake_file = FileSystem.find(@file)
|
199
|
+
@__lstat = __lstat
|
200
|
+
@ctime = @fake_file.ctime
|
201
|
+
@mtime = @fake_file.mtime
|
190
202
|
end
|
191
203
|
|
192
204
|
def symlink?
|
@@ -198,7 +210,15 @@ module FakeFS
|
|
198
210
|
end
|
199
211
|
|
200
212
|
def nlink
|
201
|
-
|
213
|
+
@fake_file.links.size
|
214
|
+
end
|
215
|
+
|
216
|
+
def size
|
217
|
+
if @__lstat && symlink?
|
218
|
+
@fake_file.target.size
|
219
|
+
else
|
220
|
+
File.size(@file)
|
221
|
+
end
|
202
222
|
end
|
203
223
|
end
|
204
224
|
|
@@ -208,45 +228,119 @@ module FakeFS
|
|
208
228
|
@path = path
|
209
229
|
@mode = mode
|
210
230
|
@file = FileSystem.find(path)
|
211
|
-
@
|
231
|
+
@autoclose = true
|
212
232
|
|
213
233
|
check_modes!
|
214
234
|
|
215
235
|
file_creation_mode? ? create_missing_file : check_file_existence!
|
216
236
|
|
217
|
-
|
237
|
+
super(@file.content, mode)
|
238
|
+
end
|
239
|
+
|
240
|
+
def exists?
|
241
|
+
true
|
218
242
|
end
|
219
243
|
|
220
|
-
|
221
|
-
|
244
|
+
alias_method :tell=, :pos=
|
245
|
+
alias_method :sysread, :read
|
246
|
+
alias_method :syswrite, :write
|
247
|
+
|
248
|
+
undef_method :closed_read?
|
249
|
+
undef_method :closed_write?
|
250
|
+
undef_method :length
|
251
|
+
undef_method :size
|
252
|
+
undef_method :string
|
253
|
+
undef_method :string=
|
254
|
+
|
255
|
+
def ioctl(integer_cmd, arg)
|
256
|
+
raise NotImplementedError
|
222
257
|
end
|
223
258
|
|
224
|
-
def
|
225
|
-
|
259
|
+
def read_nonblock(maxlen, outbuf = nil)
|
260
|
+
raise NotImplementedError
|
226
261
|
end
|
227
262
|
|
228
|
-
def
|
229
|
-
@
|
263
|
+
def stat
|
264
|
+
self.class.stat(@path)
|
230
265
|
end
|
231
266
|
|
232
|
-
def
|
233
|
-
|
267
|
+
def lstat
|
268
|
+
self.class.lstat(@path)
|
234
269
|
end
|
235
270
|
|
236
|
-
def
|
237
|
-
|
271
|
+
def sysseek(position, whence = SEEK_SET)
|
272
|
+
seek(position, whence)
|
273
|
+
pos
|
238
274
|
end
|
239
275
|
|
240
|
-
|
241
|
-
|
276
|
+
alias_method :to_i, :fileno
|
277
|
+
|
278
|
+
def to_io
|
279
|
+
self
|
242
280
|
end
|
243
|
-
alias_method :print, :write
|
244
|
-
alias_method :<<, :write
|
245
281
|
|
246
|
-
def
|
282
|
+
def write_nonblock(string)
|
283
|
+
raise NotImplementedError
|
284
|
+
end
|
247
285
|
|
248
|
-
def
|
249
|
-
|
286
|
+
def readpartial(maxlen, outbuf = nil)
|
287
|
+
raise NotImplementedError
|
288
|
+
end
|
289
|
+
|
290
|
+
def atime
|
291
|
+
raise NotImplementedError
|
292
|
+
end
|
293
|
+
|
294
|
+
def chmod(mode_int)
|
295
|
+
raise NotImplementedError
|
296
|
+
end
|
297
|
+
|
298
|
+
def chown(owner_int, group_int)
|
299
|
+
raise NotImplementedError
|
300
|
+
end
|
301
|
+
|
302
|
+
def ctime
|
303
|
+
self.class.ctime(@path)
|
304
|
+
end
|
305
|
+
|
306
|
+
def flock(locking_constant)
|
307
|
+
raise NotImplementedError
|
308
|
+
end
|
309
|
+
|
310
|
+
def mtime
|
311
|
+
self.class.mtime(@path)
|
312
|
+
end
|
313
|
+
|
314
|
+
if RUBY_VERSION >= "1.9"
|
315
|
+
def binmode?
|
316
|
+
raise NotImplementedError
|
317
|
+
end
|
318
|
+
|
319
|
+
def close_on_exec=(bool)
|
320
|
+
raise NotImplementedError
|
321
|
+
end
|
322
|
+
|
323
|
+
def close_on_exec?
|
324
|
+
raise NotImplementedError
|
325
|
+
end
|
326
|
+
|
327
|
+
def to_path
|
328
|
+
raise NotImplementedError
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
if RUBY_VERSION >= "1.9.2"
|
333
|
+
attr_writer :autoclose
|
334
|
+
|
335
|
+
def autoclose?
|
336
|
+
@autoclose
|
337
|
+
end
|
338
|
+
|
339
|
+
alias_method :fdatasync, :flush
|
340
|
+
|
341
|
+
def size
|
342
|
+
File.size(@path)
|
343
|
+
end
|
250
344
|
end
|
251
345
|
|
252
346
|
private
|