fakefs 0.6.5 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.travis.yml +3 -1
- data/CONTRIBUTORS +16 -16
- data/README.markdown +1 -1
- data/Rakefile +2 -2
- data/fakefs.gemspec +2 -0
- data/lib/fakefs/base.rb +7 -5
- data/lib/fakefs/fake/file.rb +11 -10
- data/lib/fakefs/file.rb +21 -0
- data/lib/fakefs/file_system.rb +2 -1
- data/lib/fakefs/version.rb +1 -1
- data/test/dir/tempfile_test.rb +4 -5
- data/test/fake/file/join_test.rb +1 -1
- data/test/fake/file/lstat_test.rb +3 -3
- data/test/fake/file/stat_test.rb +1 -1
- data/test/fake/file/sysseek_test.rb +1 -1
- data/test/fake/file/syswrite_test.rb +1 -1
- data/test/fake/file_test.rb +2 -2
- data/test/fake/symlink_test.rb +4 -4
- data/test/fakefs_test.rb +173 -160
- data/test/file/stat_test.rb +7 -7
- data/test/kernel_test.rb +1 -1
- data/test/pathname_test.rb +3 -3
- data/test/safe_test.rb +7 -7
- data/test/test_helper.rb +13 -12
- data/test/verify.rb +3 -3
- metadata +46 -18
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YzFhYTRmZmU1NTY3MWJlZTljZjkyZTBjMmQ4NjBiZWZhNDBiNDg1YQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fc6809d0301720e85b2242f8e37100be5e77395b
|
4
|
+
data.tar.gz: 63eaa2bfd50a523613ec164fdbcfbbd14195aeae
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YzIzYTc0YmFlMThjYmY5Yjk4OWQwZWM0ZTU2YTI4ZGJiNDEzNzA3M2NkYjEy
|
11
|
-
YzljYmJiY2EzOGNiNTBhZTdkOWY5M2FmZjEzZWFmNDQ4ODg1ZGI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ODRiYzE1NjBhZjRjMGVhNTE1YWE1ZmM0YmRjMjZkNzAwNDcwYTkzNjRmNjJh
|
14
|
-
MDNkODk2MzVlNTVhZWVmODFjNjhkMTEzNGZjNGYyOGNiODFhMzg3YThhOTg4
|
15
|
-
N2E3Y2JlM2I3NzI2ZWQ1YTY1ZjNkMzhhYzc2ZTgzYzU0ZjY1MTQ=
|
6
|
+
metadata.gz: cd81047918fe4c89615fc92c5e5b57c5c7953c367c61c2e9b823c7b4bc8079fc82fa08048dca9cb17cffefd17b19a7b1a0f69740d1345658d047b2ceb34d16a4
|
7
|
+
data.tar.gz: 0a7cddc534cf1a1430392d95b8c17301ddb3f5cb233da7481da62401ef97e8995cd11522a030f04899aa932630bb976e68506fe36decac49c3d5c55db93d56e2
|
data/.travis.yml
CHANGED
data/CONTRIBUTORS
CHANGED
@@ -6,6 +6,7 @@ Lukas Oberhuber <lukaso@gmail.com>
|
|
6
6
|
Brian Donovan <donovan@squareup.com>
|
7
7
|
Myles Eftos <myles@madpilot.com.au>
|
8
8
|
Jeff Hodges <jeff@somethingsimilar.com>
|
9
|
+
Jakub Jirutka <jakub@jirutka.cz>
|
9
10
|
Pierre RAMBAUD <pierre.rambaud86@gmail.com>
|
10
11
|
Morten Møller Riis <mortenmoellerriis@gmail.com>
|
11
12
|
Matt Freels <matt@freels.name>
|
@@ -32,9 +33,9 @@ Maarten Hoogendoorn <maarten@moretea.nl>
|
|
32
33
|
Jon Yurek <jyurek@thoughtbot.com>
|
33
34
|
Jared Luxenberg <jared@jaredlux.com>
|
34
35
|
DSIW <dsiw@dsiw-it.de>
|
35
|
-
Lars Gierth <lars.gierth@gmail.com>
|
36
|
-
Greg Campbell <gtcampbell@gmail.com>
|
37
36
|
doc75 <github@virlet.org>
|
37
|
+
Greg Campbell <gtcampbell@gmail.com>
|
38
|
+
Lars Gierth <lars.gierth@gmail.com>
|
38
39
|
marano <thiagomarano@gmail.com>
|
39
40
|
Ben Mabey <ben@benmabey.com>
|
40
41
|
Jorge Orlando Munoz <jmunoz@altavistaed.com>
|
@@ -43,11 +44,10 @@ Sam Goldstein <sam@aboutus.org>
|
|
43
44
|
Adam Alboyadjian <adam@vistahigherlearning.com>
|
44
45
|
Rick Salevsky <rsalevsky@suse.com>
|
45
46
|
Scott Petersen <petersen@centtech.com>
|
46
|
-
Emil Soman <emil.soman@gmail.com>
|
47
|
-
Ryan McGeary <ryan@mcgeary.org>
|
48
47
|
Matt Todd <chiology@gmail.com>
|
49
48
|
Noah Paessel <knowuh@gmail.com>
|
50
|
-
|
49
|
+
Emil Soman <emil.soman@gmail.com>
|
50
|
+
Ryan McGeary <ryan@mcgeary.org>
|
51
51
|
dmathieu <42@dmathieu.com>
|
52
52
|
Oleg Sukhodolsky <os97673@gmail.com>
|
53
53
|
Winston Lee <lee.winston@gmail.com>
|
@@ -56,37 +56,37 @@ Grayson Wright <wright.grayson@gmail.com>
|
|
56
56
|
Zequez <zequez@gmail.com>
|
57
57
|
jameswilding <james@jameswilding.net>
|
58
58
|
Ed Ruder <ed@squareup.com>
|
59
|
-
Benjamin Oakes <hello@benjaminoakes.com>
|
60
59
|
Tymon Tobolski <i@teamon.eu>
|
60
|
+
Benjamin Oakes <hello@benjaminoakes.com>
|
61
61
|
Scott Barron <scott@elitists.net>
|
62
62
|
Andrius Chamentauskas <andrius.chamentauskas@gmail.com>
|
63
63
|
Eric Daspet <eric.daspet@survol.fr>
|
64
|
+
W. Andrew Loe III <andrew@andrewloe.com>
|
64
65
|
Matt Hoyle <matt@deployable.co>
|
65
66
|
Xavier Shay <xavier@squareup.com>
|
66
|
-
W. Andrew Loe III <andrew@andrewloe.com>
|
67
67
|
Travis Herrick <travis@carbonfive.com>
|
68
68
|
Keita Urashima <ursm@ursm.jp>
|
69
69
|
rambutan <usul@usul-HP-EliteBook-8460p.(none)>
|
70
|
-
andrea longhi <andrea@spaghetticode.it>
|
71
|
-
= <gokulnath@mobme.in>
|
72
70
|
Matthew Morgan <lytithwyn@gmail.com>
|
71
|
+
= <gokulnath@mobme.in>
|
72
|
+
andrea longhi <andrea@spaghetticode.it>
|
73
73
|
msassak <msassak@gmail.com>
|
74
74
|
David Reese <david@whatcould.com>
|
75
|
-
Andrius Chamentauskas <sinsiliux@gmail.com>
|
76
75
|
timo3377 <tim.linquist@gmail.com>
|
76
|
+
Andrius Chamentauskas <sinsiliux@gmail.com>
|
77
|
+
Paolo Gianrossi <paolino.gianrossi@gmail.com>
|
77
78
|
Matt Rogers <mattrogers@sbcglobal.net>
|
78
79
|
Michael Scherer <misc@zarb.org>
|
79
|
-
Paolo Gianrossi <paolino.gianrossi@gmail.com>
|
80
80
|
Mislav Marohnić <mislav.marohnic@gmail.com>
|
81
|
-
Rob Sanheim <rsanheim@gmail.com>
|
82
81
|
Andrew Ryan <nerdrew@gmail.com>
|
82
|
+
Rob Sanheim <rsanheim@gmail.com>
|
83
|
+
Chris Wanstrath <chris@github.com>
|
84
|
+
Chris Knadler <takeshi91k@gmail.com>
|
83
85
|
Toon Willems <willemstoon@gmail.com>
|
84
86
|
Ryan Scott Lewis <ryanscottlewis@lewis-software.com>
|
85
|
-
Chris Knadler <takeshi91k@gmail.com>
|
86
|
-
Chris Wanstrath <chris@github.com>
|
87
|
-
Yuta Shimizu <pachirel@gmail.com>
|
88
87
|
Sven Riedel <sr@gimp.org>
|
89
88
|
Dane O'Connor <dane.oconnor@gmail.com>
|
89
|
+
Yuta Shimizu <pachirel@gmail.com>
|
90
|
+
Benjamin Fleischer <github@benjaminfleischer.com>
|
90
91
|
Jordi Massaguer Pla <jmassaguerpla@suse.de>
|
91
92
|
Maria Shaldibina <mariash@pivotallabs.com>
|
92
|
-
Benjamin Fleischer <github@benjaminfleischer.com>
|
data/README.markdown
CHANGED
data/Rakefile
CHANGED
@@ -30,7 +30,7 @@ end
|
|
30
30
|
task default: [:test, :spec, :rubocop]
|
31
31
|
|
32
32
|
desc 'Push a new version to rubygems.org'
|
33
|
-
task :publish => [:test, :spec, :update_contributors, :tag, :release, :push]
|
33
|
+
task :publish => [:test, :spec, :rubocop, :update_contributors, :tag, :release, :push]
|
34
34
|
|
35
35
|
desc 'Update contributors'
|
36
36
|
task :update_contributors do
|
@@ -39,7 +39,7 @@ task :update_contributors do
|
|
39
39
|
sh "#{git_rank_contributors} > CONTRIBUTORS"
|
40
40
|
if `git status | grep CONTRIBUTORS`.strip.length > 0
|
41
41
|
sh "git add CONTRIBUTORS"
|
42
|
-
sh "git commit -m '
|
42
|
+
sh "git commit -m 'Update contributors for release'"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
data/fakefs.gemspec
CHANGED
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake", "~> 10.3"
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.1"
|
24
24
|
spec.add_development_dependency 'rubocop', '~>0.25'
|
25
|
+
spec.add_development_dependency 'minitest', '~> 5.5'
|
26
|
+
spec.add_development_dependency 'minitest-rg', '~> 5.1'
|
25
27
|
end
|
data/lib/fakefs/base.rb
CHANGED
@@ -16,14 +16,12 @@ end
|
|
16
16
|
|
17
17
|
# FakeFS module
|
18
18
|
module FakeFS
|
19
|
-
@activated = false
|
20
19
|
class << self
|
21
20
|
def activated?
|
22
|
-
@activated
|
21
|
+
@activated ? true : false
|
23
22
|
end
|
24
23
|
|
25
24
|
def activate!
|
26
|
-
@activated = true
|
27
25
|
Object.class_eval do
|
28
26
|
remove_const(:Dir)
|
29
27
|
remove_const(:File)
|
@@ -38,12 +36,13 @@ module FakeFS
|
|
38
36
|
const_set(:Pathname, FakeFS::Pathname) if RUBY_VERSION >= '1.9.3'
|
39
37
|
::FakeFS::Kernel.hijack!
|
40
38
|
end
|
39
|
+
|
40
|
+
@activated = true
|
41
|
+
|
41
42
|
true
|
42
43
|
end
|
43
44
|
|
44
45
|
def deactivate!
|
45
|
-
@activated = false
|
46
|
-
|
47
46
|
Object.class_eval do
|
48
47
|
remove_const(:Dir)
|
49
48
|
remove_const(:File)
|
@@ -58,6 +57,9 @@ module FakeFS
|
|
58
57
|
const_set(:Pathname, RealPathname) if RUBY_VERSION >= '1.9.3'
|
59
58
|
::FakeFS::Kernel.unhijack!
|
60
59
|
end
|
60
|
+
|
61
|
+
@activated = false
|
62
|
+
|
61
63
|
true
|
62
64
|
end
|
63
65
|
|
data/lib/fakefs/fake/file.rb
CHANGED
@@ -2,7 +2,7 @@ module FakeFS
|
|
2
2
|
# Fake file class
|
3
3
|
class FakeFile
|
4
4
|
attr_accessor :name, :parent, :content, :mtime, :atime, :mode, :uid, :gid
|
5
|
-
attr_reader :ctime
|
5
|
+
attr_reader :ctime, :birthtime
|
6
6
|
|
7
7
|
# Inode class
|
8
8
|
class Inode
|
@@ -34,15 +34,16 @@ module FakeFS
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def initialize(name = nil, parent = nil)
|
37
|
-
@name
|
38
|
-
@parent
|
39
|
-
@inode
|
40
|
-
@ctime
|
41
|
-
@mtime
|
42
|
-
@atime
|
43
|
-
@
|
44
|
-
@
|
45
|
-
@
|
37
|
+
@name = name
|
38
|
+
@parent = parent
|
39
|
+
@inode = Inode.new(self)
|
40
|
+
@ctime = Time.now
|
41
|
+
@mtime = @ctime
|
42
|
+
@atime = @ctime
|
43
|
+
@birthtime = @ctime
|
44
|
+
@mode = 0100000 + (0666 - File.umask)
|
45
|
+
@uid = Process.uid
|
46
|
+
@gid = Process.gid
|
46
47
|
end
|
47
48
|
|
48
49
|
attr_accessor :inode
|
data/lib/fakefs/file.rb
CHANGED
@@ -283,6 +283,7 @@ module FakeFS
|
|
283
283
|
# FakeFS Stat class
|
284
284
|
class Stat
|
285
285
|
attr_reader :ctime, :mtime, :atime, :mode, :uid, :gid
|
286
|
+
attr_reader :birthtime if RUBY_VERSION >= '2.2.0'
|
286
287
|
|
287
288
|
def initialize(file, lstat = false)
|
288
289
|
fail(Errno::ENOENT, file) unless File.exist?(file)
|
@@ -296,6 +297,12 @@ module FakeFS
|
|
296
297
|
@mode = @fake_file.mode
|
297
298
|
@uid = @fake_file.uid
|
298
299
|
@gid = @fake_file.gid
|
300
|
+
@birthtime =
|
301
|
+
if @fake_file.respond_to?(:birthtime)
|
302
|
+
@fake_file.birthtime
|
303
|
+
else
|
304
|
+
@fake_file.ctime
|
305
|
+
end
|
299
306
|
end
|
300
307
|
|
301
308
|
def symlink?
|
@@ -553,6 +560,20 @@ module FakeFS
|
|
553
560
|
end
|
554
561
|
end
|
555
562
|
|
563
|
+
if RUBY_VERSION >= '2.2.0'
|
564
|
+
def self.birthtime(path)
|
565
|
+
if exists?(path)
|
566
|
+
FileSystem.find(path).birthtime
|
567
|
+
else
|
568
|
+
fail Errno::ENOENT
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
def birthtime
|
573
|
+
self.class.birthtime(@path)
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
556
577
|
def read(length = nil, buf = '')
|
557
578
|
read_buf = super(length, buf)
|
558
579
|
# change to binary only for ruby 1.9.3
|
data/lib/fakefs/file_system.rb
CHANGED
@@ -60,12 +60,13 @@ module FakeFS
|
|
60
60
|
|
61
61
|
files.each do |f|
|
62
62
|
target_path = target ? f.gsub(path, target) : f
|
63
|
+
|
63
64
|
if RealFile.symlink?(f)
|
64
65
|
FileUtils.ln_s(RealFile.readlink(f), f)
|
65
66
|
elsif RealFile.file?(f)
|
66
67
|
FileUtils.mkdir_p(File.dirname(f))
|
67
68
|
File.open(target_path, File::WRITE_ONLY) do |g|
|
68
|
-
g.print RealFile.
|
69
|
+
g.print RealFile.read(f)
|
69
70
|
end
|
70
71
|
elsif RealFile.directory?(f)
|
71
72
|
FileUtils.mkdir_p(target_path)
|
data/lib/fakefs/version.rb
CHANGED
data/test/dir/tempfile_test.rb
CHANGED
@@ -2,16 +2,15 @@ require 'test_helper'
|
|
2
2
|
require 'tempfile'
|
3
3
|
|
4
4
|
# Tempfile test class
|
5
|
-
class TempfileTest < Test
|
5
|
+
class TempfileTest < Minitest::Test
|
6
6
|
include FakeFS
|
7
7
|
|
8
8
|
if RUBY_VERSION >= '2.1'
|
9
9
|
def test_should_not_raise_error
|
10
10
|
FakeFS do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
11
|
+
# nothing raised
|
12
|
+
FileUtils.mkdir_p('/tmp')
|
13
|
+
Tempfile.open('test')
|
15
14
|
end
|
16
15
|
end
|
17
16
|
else
|
data/test/fake/file/join_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
# File stat test class
|
4
|
-
class FileStat < Test
|
4
|
+
class FileStat < Minitest::Test
|
5
5
|
def setup
|
6
6
|
FakeFS.activate!
|
7
7
|
FakeFS::FileSystem.clear
|
@@ -35,7 +35,7 @@ class FileStat < Test::Unit::TestCase
|
|
35
35
|
File.open('foo', 'w') { |f| f << 'some content' }
|
36
36
|
File.symlink 'foo', 'my_symlink'
|
37
37
|
|
38
|
-
|
38
|
+
refute_equal File.lstat('my_symlink').size, File.lstat('foo').size
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_should_report_on_symlink_itself_with_size_instance_method
|
@@ -45,7 +45,7 @@ class FileStat < Test::Unit::TestCase
|
|
45
45
|
file = File.open('foo')
|
46
46
|
symlink = File.open('my_symlink')
|
47
47
|
|
48
|
-
|
48
|
+
refute_equal file.lstat.size, symlink.lstat.size
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_symlink_size_is_size_of_path_pointed_to
|
data/test/fake/file/stat_test.rb
CHANGED
data/test/fake/file_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
# Fake File test class
|
4
|
-
class FakeFileTest < Test
|
4
|
+
class FakeFileTest < Minitest::Test
|
5
5
|
include FakeFS
|
6
6
|
|
7
7
|
def setup
|
@@ -72,7 +72,7 @@ class FakeFileTest < Test::Unit::TestCase
|
|
72
72
|
|
73
73
|
def test_clone_creates_new_inode
|
74
74
|
clone = @file.clone
|
75
|
-
|
75
|
+
refute clone.inode.equal?(@file.inode)
|
76
76
|
end
|
77
77
|
|
78
78
|
def test_cloning_does_not_use_same_content_object
|
data/test/fake/symlink_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
# Fake symlink test class
|
4
|
-
class FakeSymlinkTest < Test
|
4
|
+
class FakeSymlinkTest < Minitest::Test
|
5
5
|
include FakeFS
|
6
6
|
|
7
7
|
def test_symlink_has_method_missing_as_private
|
@@ -15,7 +15,7 @@ class FakeSymlinkTest < Test::Unit::TestCase
|
|
15
15
|
'has public method \#to_s'
|
16
16
|
assert fake_symlink.respond_to?(:to_s, true),
|
17
17
|
'has public or private method \#to_s'
|
18
|
-
|
18
|
+
refute fake_symlink.respond_to?(:initialize, false),
|
19
19
|
'has private method \#initialize'
|
20
20
|
assert fake_symlink.respond_to?(:initialize, true),
|
21
21
|
'has private method \#initialize'
|
@@ -25,8 +25,8 @@ class FakeSymlinkTest < Test::Unit::TestCase
|
|
25
25
|
fake_symlink = FakeSymlink.new('foo')
|
26
26
|
assert_equal fake_symlink.respond_to?(:to_s),
|
27
27
|
fake_symlink.entry.respond_to?(:to_s)
|
28
|
-
|
29
|
-
|
28
|
+
refute_equal fake_symlink.respond_to?(:to_s),
|
29
|
+
fake_symlink.entry.respond_to?(:initialize)
|
30
30
|
assert_equal fake_symlink.respond_to?(:initialize),
|
31
31
|
fake_symlink.entry.respond_to?(:initialize)
|
32
32
|
end
|
data/test/fakefs_test.rb
CHANGED
@@ -2,32 +2,41 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
4
|
# FakeFS tests
|
5
|
-
class FakeFSTest < Test
|
6
|
-
include FakeFS
|
7
|
-
|
5
|
+
class FakeFSTest < Minitest::Test
|
8
6
|
def setup
|
7
|
+
act_on_real_fs do
|
8
|
+
File.umask(0006)
|
9
|
+
FileUtils.rm_rf(real_file_sandbox)
|
10
|
+
FileUtils.mkdir_p(real_file_sandbox)
|
11
|
+
FileUtils.chmod(0777, real_file_sandbox)
|
12
|
+
end
|
13
|
+
|
9
14
|
FakeFS.activate!
|
10
|
-
FileSystem.clear
|
15
|
+
FakeFS::FileSystem.clear
|
11
16
|
end
|
12
17
|
|
13
18
|
def teardown
|
14
19
|
FakeFS.deactivate!
|
20
|
+
|
21
|
+
act_on_real_fs do
|
22
|
+
FileUtils.rm_rf(real_file_sandbox)
|
23
|
+
end
|
15
24
|
end
|
16
25
|
|
17
26
|
def test_can_be_initialized_empty
|
18
|
-
fs = FileSystem
|
27
|
+
fs = FakeFS::FileSystem
|
19
28
|
assert_equal 0, fs.files.size
|
20
29
|
end
|
21
30
|
|
22
31
|
def xtest_can_be_initialized_with_an_existing_directory
|
23
|
-
fs = FileSystem
|
32
|
+
fs = FakeFS::FileSystem
|
24
33
|
fs.clone(File.expand_path(File.dirname(__FILE__))).inspect
|
25
34
|
assert_equal 1, fs.files.size
|
26
35
|
end
|
27
36
|
|
28
37
|
def test_can_create_directories_with_file_utils_mkdir_p
|
29
38
|
FileUtils.mkdir_p('/path/to/dir')
|
30
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
|
39
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir']
|
31
40
|
end
|
32
41
|
|
33
42
|
def test_can_cd_to_directory_with_block
|
@@ -42,26 +51,26 @@ class FakeFSTest < Test::Unit::TestCase
|
|
42
51
|
|
43
52
|
def test_can_create_a_list_of_directories_with_file_utils_mkdir_p
|
44
53
|
FileUtils.mkdir_p(%w(/path/to/dir1 /path/to/dir2))
|
45
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir1']
|
46
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir2']
|
54
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir1']
|
55
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir2']
|
47
56
|
end
|
48
57
|
|
49
58
|
def test_can_create_directories_with_options
|
50
59
|
FileUtils.mkdir_p('/path/to/dir', mode: 0755)
|
51
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
|
60
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir']
|
52
61
|
end
|
53
62
|
|
54
63
|
def test_can_create_directories_with_file_utils_mkdir
|
55
64
|
FileUtils.mkdir_p('/path/to/dir')
|
56
65
|
FileUtils.mkdir('/path/to/dir/subdir')
|
57
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']['subdir']
|
66
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir']['subdir']
|
58
67
|
end
|
59
68
|
|
60
69
|
def test_can_create_a_list_of_directories_with_file_utils_mkdir
|
61
70
|
FileUtils.mkdir_p('/path/to/dir')
|
62
71
|
FileUtils.mkdir(%w(/path/to/dir/subdir1 /path/to/dir/subdir2))
|
63
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']['subdir1']
|
64
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']['subdir2']
|
72
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir']['subdir1']
|
73
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir']['subdir2']
|
65
74
|
end
|
66
75
|
|
67
76
|
def test_raises_error_when_creating_a_new_dir_with_mkdir_in_non_existent_path
|
@@ -73,54 +82,50 @@ class FakeFSTest < Test::Unit::TestCase
|
|
73
82
|
def test_raises_error_when_creating_a_new_dir_over_existing_file
|
74
83
|
File.open('file', 'w') { |f| f << 'This is a file, not a directory.' }
|
75
84
|
|
76
|
-
|
85
|
+
assert_raises Errno::EEXIST do
|
77
86
|
FileUtils.mkdir_p('file/subdir')
|
78
87
|
end
|
79
88
|
|
80
89
|
FileUtils.mkdir('dir')
|
81
90
|
File.open('dir/subfile', 'w') { |f| f << 'This is a file inside a directory.' }
|
82
91
|
|
83
|
-
|
92
|
+
assert_raises Errno::EEXIST do
|
84
93
|
FileUtils.mkdir_p('dir/subfile/subdir')
|
85
94
|
end
|
86
95
|
end
|
87
96
|
|
88
97
|
def test_can_create_directories_with_mkpath
|
89
98
|
FileUtils.mkpath('/path/to/dir')
|
90
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
|
99
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir']
|
91
100
|
end
|
92
101
|
|
93
102
|
def test_can_create_directories_with_mkpath_and_options
|
94
103
|
FileUtils.mkpath('/path/to/dir', mode: 0755)
|
95
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
|
104
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir']
|
96
105
|
end
|
97
106
|
|
98
107
|
def test_can_create_directories_with_mkdirs
|
99
108
|
FileUtils.makedirs('/path/to/dir')
|
100
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
|
109
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir']
|
101
110
|
end
|
102
111
|
|
103
112
|
def test_can_create_directories_with_mkdirs_and_options
|
104
113
|
FileUtils.makedirs('/path/to/dir', mode: 0755)
|
105
|
-
assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
|
114
|
+
assert_kind_of FakeFS::FakeDir, FakeFS::FileSystem.fs['path']['to']['dir']
|
106
115
|
end
|
107
116
|
|
108
117
|
def test_unlink_errors_on_file_not_found
|
109
|
-
|
118
|
+
assert_raises Errno::ENOENT do
|
110
119
|
FileUtils.rm('/foo')
|
111
120
|
end
|
112
121
|
end
|
113
122
|
|
114
123
|
def test_unlink_doesnt_error_on_file_not_found_when_forced
|
115
|
-
|
116
|
-
FileUtils.rm('/foo', force: true)
|
117
|
-
end
|
124
|
+
FileUtils.rm('/foo', force: true)
|
118
125
|
end
|
119
126
|
|
120
127
|
def test_unlink_doesnt_error_on_file_not_found_with_rm_rf
|
121
|
-
|
122
|
-
FileUtils.rm_rf('/foo')
|
123
|
-
end
|
128
|
+
FileUtils.rm_rf('/foo')
|
124
129
|
end
|
125
130
|
|
126
131
|
def test_can_delete_directories
|
@@ -199,13 +204,13 @@ class FakeFSTest < Test::Unit::TestCase
|
|
199
204
|
|
200
205
|
def test_symlink_with_missing_refferent_does_not_exist
|
201
206
|
File.symlink('/foo', '/bar')
|
202
|
-
|
207
|
+
refute File.exist?('/bar')
|
203
208
|
end
|
204
209
|
|
205
210
|
def test_can_create_symlinks
|
206
211
|
FileUtils.mkdir_p(target = '/path/to/target')
|
207
212
|
FileUtils.ln_s(target, '/path/to/link')
|
208
|
-
assert_kind_of FakeSymlink, FileSystem.fs['path']['to']['link']
|
213
|
+
assert_kind_of FakeFS::FakeSymlink, FakeFS::FileSystem.fs['path']['to']['link']
|
209
214
|
|
210
215
|
assert_raises(Errno::EEXIST) do
|
211
216
|
FileUtils.ln_s(target, '/path/to/link')
|
@@ -215,14 +220,14 @@ class FakeFSTest < Test::Unit::TestCase
|
|
215
220
|
def test_can_force_creation_of_symlinks
|
216
221
|
FileUtils.mkdir_p(target = '/path/to/first/target')
|
217
222
|
FileUtils.ln_s(target, '/path/to/link')
|
218
|
-
assert_kind_of FakeSymlink, FileSystem.fs['path']['to']['link']
|
223
|
+
assert_kind_of FakeFS::FakeSymlink, FakeFS::FileSystem.fs['path']['to']['link']
|
219
224
|
FileUtils.ln_s(target, '/path/to/link', force: true)
|
220
225
|
end
|
221
226
|
|
222
227
|
def test_create_symlink_using_ln_sf
|
223
228
|
FileUtils.mkdir_p(target = '/path/to/first/target')
|
224
229
|
FileUtils.ln_s(target, '/path/to/link')
|
225
|
-
assert_kind_of FakeSymlink, FileSystem.fs['path']['to']['link']
|
230
|
+
assert_kind_of FakeFS::FakeSymlink, FakeFS::FileSystem.fs['path']['to']['link']
|
226
231
|
FileUtils.ln_sf(target, '/path/to/link')
|
227
232
|
end
|
228
233
|
|
@@ -251,7 +256,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
251
256
|
FileUtils.touch('/file')
|
252
257
|
FileUtils.mkdir_p('/a/b')
|
253
258
|
FileUtils.ln_s('../../file_foo', '/a/b/symlink')
|
254
|
-
|
259
|
+
refute File.exist?('/a/b/symlink')
|
255
260
|
end
|
256
261
|
|
257
262
|
def test_symlink_with_relative_path_has_correct_target
|
@@ -274,9 +279,9 @@ class FakeFSTest < Test::Unit::TestCase
|
|
274
279
|
def test_symlink_to_symlinks_should_raise_error_if_dir_doesnt_exist
|
275
280
|
FileUtils.mkdir_p(target = '/path/to/foo/target')
|
276
281
|
|
277
|
-
|
282
|
+
refute Dir.exist?('/path/to/bar')
|
278
283
|
|
279
|
-
|
284
|
+
assert_raises Errno::ENOENT do
|
280
285
|
FileUtils.ln_s(target, '/path/to/bar/symlink')
|
281
286
|
end
|
282
287
|
end
|
@@ -299,7 +304,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
299
304
|
end
|
300
305
|
|
301
306
|
def test_nothing_is_sticky
|
302
|
-
|
307
|
+
refute File.sticky?('/')
|
303
308
|
end
|
304
309
|
|
305
310
|
def test_can_create_files_in_existing_dir
|
@@ -496,7 +501,8 @@ class FakeFSTest < Test::Unit::TestCase
|
|
496
501
|
f.write 'Yatta!'
|
497
502
|
end
|
498
503
|
|
499
|
-
|
504
|
+
# nothing raised
|
505
|
+
File.read(path, mode: 'r:UTF-8:-')
|
500
506
|
end
|
501
507
|
|
502
508
|
def test_file_read_respects_args
|
@@ -519,7 +525,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
519
525
|
end
|
520
526
|
|
521
527
|
def test_raises_error_when_opening_with_binary_mode_only
|
522
|
-
|
528
|
+
assert_raises ArgumentError do
|
523
529
|
File.open('/foo', 'b')
|
524
530
|
end
|
525
531
|
end
|
@@ -598,7 +604,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
598
604
|
end
|
599
605
|
|
600
606
|
def test_raises_error_on_mtime_if_file_does_not_exist
|
601
|
-
|
607
|
+
assert_raises Errno::ENOENT do
|
602
608
|
File.mtime('/path/to/file.txt')
|
603
609
|
end
|
604
610
|
end
|
@@ -630,7 +636,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
630
636
|
end
|
631
637
|
|
632
638
|
def test_raises_error_on_ctime_if_file_does_not_exist
|
633
|
-
|
639
|
+
assert_raises Errno::ENOENT do
|
634
640
|
File.ctime('file.txt')
|
635
641
|
end
|
636
642
|
end
|
@@ -641,7 +647,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
641
647
|
end
|
642
648
|
|
643
649
|
def test_raises_error_on_atime_if_file_does_not_exist
|
644
|
-
|
650
|
+
assert_raises Errno::ENOENT do
|
645
651
|
File.atime('file.txt')
|
646
652
|
end
|
647
653
|
end
|
@@ -713,7 +719,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
713
719
|
end
|
714
720
|
|
715
721
|
def test_utime_raises_error_if_path_does_not_exist
|
716
|
-
|
722
|
+
assert_raises Errno::ENOENT do
|
717
723
|
File.utime(Time.now, Time.now, '/path/to/file.txt')
|
718
724
|
end
|
719
725
|
end
|
@@ -787,7 +793,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
787
793
|
file = File.open(path, 'w')
|
788
794
|
file.write 'Yada'
|
789
795
|
file.close
|
790
|
-
|
796
|
+
assert_raises IOError do
|
791
797
|
file.read
|
792
798
|
end
|
793
799
|
end
|
@@ -797,7 +803,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
797
803
|
file = File.open(path, 'w')
|
798
804
|
file.write 'Yada'
|
799
805
|
file.close
|
800
|
-
|
806
|
+
assert_raises IOError do
|
801
807
|
file << 'foo'
|
802
808
|
end
|
803
809
|
end
|
@@ -821,17 +827,14 @@ class FakeFSTest < Test::Unit::TestCase
|
|
821
827
|
end
|
822
828
|
|
823
829
|
def test_file_object_initialization_with_mode_in_hash_parameter
|
824
|
-
|
825
|
-
File.open('file.txt', mode: 'w') { |f| f.write 'Yatta!' }
|
826
|
-
end
|
830
|
+
File.open('file.txt', mode: 'w') { |f| f.write 'Yatta!' }
|
827
831
|
end
|
828
832
|
|
829
833
|
def test_file_object_initialization_with_brackets_in_filename
|
830
834
|
filename = 'bracket[1](2).txt'
|
831
835
|
expected_contents = 'Yokudekimashita'
|
832
|
-
|
833
|
-
|
834
|
-
end
|
836
|
+
# nothing raised
|
837
|
+
File.open(filename, mode: 'w') { |f| f.write "#{expected_contents}" }
|
835
838
|
the_file = Dir['/*']
|
836
839
|
assert_equal the_file.length, 1
|
837
840
|
assert_equal the_file[0], "/#{filename}"
|
@@ -842,15 +845,14 @@ class FakeFSTest < Test::Unit::TestCase
|
|
842
845
|
def test_file_object_initialization_with_brackets_in_filename
|
843
846
|
filename = "\u65e5\u672c\u8a9e.txt"
|
844
847
|
expected_contents = 'Yokudekimashita'
|
845
|
-
|
846
|
-
|
847
|
-
end
|
848
|
+
# nothing raised
|
849
|
+
File.open(filename, mode: 'w') { |f| f.write "#{expected_contents}" }
|
848
850
|
contents = File.open("/#{filename}").read
|
849
851
|
assert_equal contents, expected_contents
|
850
852
|
end
|
851
853
|
|
852
854
|
def test_file_read_errors_appropriately
|
853
|
-
|
855
|
+
assert_raises Errno::ENOENT do
|
854
856
|
File.read('anything')
|
855
857
|
end
|
856
858
|
end
|
@@ -858,7 +860,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
858
860
|
def test_file_read_errors_on_directory
|
859
861
|
FileUtils.mkdir_p('a_directory')
|
860
862
|
|
861
|
-
|
863
|
+
assert_raises Errno::EISDIR do
|
862
864
|
File.read('a_directory')
|
863
865
|
end
|
864
866
|
end
|
@@ -918,7 +920,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
918
920
|
end
|
919
921
|
|
920
922
|
def test_executable_returns_false_for_non_existent_files
|
921
|
-
|
923
|
+
refute File.executable?('/does/not/exist')
|
922
924
|
end
|
923
925
|
|
924
926
|
def test_can_chown_files
|
@@ -1078,7 +1080,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1078
1080
|
def test_file_utils_cp_allows_noop_option
|
1079
1081
|
File.open('foo', 'w') { |f| f << 'TEST' }
|
1080
1082
|
FileUtils.cp 'foo', 'bar', noop: true
|
1081
|
-
|
1083
|
+
refute File.exist?('bar'), 'does not actually copy'
|
1082
1084
|
end
|
1083
1085
|
|
1084
1086
|
def test_file_utils_cp_raises_on_invalid_option
|
@@ -1095,7 +1097,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1095
1097
|
def test_file_utils_cp_r_allows_noop_option
|
1096
1098
|
FileUtils.touch '/foo'
|
1097
1099
|
FileUtils.cp_r '/foo', '/bar', noop: true
|
1098
|
-
|
1100
|
+
refute File.exist?('/bar'), 'does not actually copy'
|
1099
1101
|
end
|
1100
1102
|
|
1101
1103
|
def test_dir_glob_handles_root
|
@@ -1207,7 +1209,8 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1207
1209
|
:echo?, :echo=, :noecho,
|
1208
1210
|
:winsize, :winsize=,
|
1209
1211
|
:getch,
|
1210
|
-
:iflush, :ioflush, :oflush
|
1212
|
+
:iflush, :ioflush, :oflush,
|
1213
|
+
:pathconf
|
1211
1214
|
]
|
1212
1215
|
|
1213
1216
|
def test_every_method_in_file_is_in_fake_fs_file
|
@@ -1219,7 +1222,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1219
1222
|
def test_file_should_not_respond_to_string_io_unique_methods
|
1220
1223
|
uniq_string_io_methods = StringIO.instance_methods - RealFile.instance_methods
|
1221
1224
|
uniq_string_io_methods.each do |method_name|
|
1222
|
-
|
1225
|
+
refute File.instance_methods.include?(method_name), "File responds to #{method_name}"
|
1223
1226
|
end
|
1224
1227
|
end
|
1225
1228
|
|
@@ -1230,21 +1233,21 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1230
1233
|
|
1231
1234
|
def test_is_not_a_stringio
|
1232
1235
|
File.open('foo', 'w') do |f|
|
1233
|
-
|
1236
|
+
refute f.is_a?(StringIO), 'File is not a StringIO'
|
1234
1237
|
end
|
1235
1238
|
end
|
1236
1239
|
|
1237
1240
|
def test_chdir_changes_directories_like_a_boss
|
1238
1241
|
# I know memes!
|
1239
1242
|
FileUtils.mkdir_p '/path'
|
1240
|
-
assert_equal '/', FileSystem.fs.name
|
1243
|
+
assert_equal '/', FakeFS::FileSystem.fs.name
|
1241
1244
|
assert_equal [], Dir.glob('/path/*')
|
1242
1245
|
Dir.chdir '/path' do
|
1243
1246
|
File.open('foo', 'w') { |f| f.write 'foo' }
|
1244
1247
|
File.open('foobar', 'w') { |f| f.write 'foo' }
|
1245
1248
|
end
|
1246
1249
|
|
1247
|
-
assert_equal '/', FileSystem.fs.name
|
1250
|
+
assert_equal '/', FakeFS::FileSystem.fs.name
|
1248
1251
|
assert_equal(['/path/foo', '/path/foobar'], Dir.glob('/path/*').sort)
|
1249
1252
|
|
1250
1253
|
c = nil
|
@@ -1301,7 +1304,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1301
1304
|
end
|
1302
1305
|
|
1303
1306
|
def test_chdir_should_flop_over_and_die_if_the_dir_doesnt_exist
|
1304
|
-
|
1307
|
+
assert_raises(Errno::ENOENT) do
|
1305
1308
|
Dir.chdir('/nope') do
|
1306
1309
|
1
|
1307
1310
|
end
|
@@ -1331,7 +1334,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1331
1334
|
'Nothing to do'
|
1332
1335
|
end
|
1333
1336
|
|
1334
|
-
assert_equal ['/', '/path'], FileSystem.dir_levels
|
1337
|
+
assert_equal ['/', '/path'], FakeFS::FileSystem.dir_levels
|
1335
1338
|
end
|
1336
1339
|
|
1337
1340
|
assert_equal(['/path/foo', '/path/foobar'], Dir.glob('/path/*').sort)
|
@@ -1411,10 +1414,10 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1411
1414
|
end
|
1412
1415
|
|
1413
1416
|
def test_mv_should_raise_error_on_missing_file
|
1414
|
-
|
1417
|
+
assert_raises(Errno::ENOENT) do
|
1415
1418
|
FileUtils.mv 'blafgag', 'foo'
|
1416
1419
|
end
|
1417
|
-
exception =
|
1420
|
+
exception = assert_raises(Errno::ENOENT) do
|
1418
1421
|
FileUtils.mv %w(foo bar), 'destdir'
|
1419
1422
|
end
|
1420
1423
|
assert_equal 'No such file or directory - foo', exception.message
|
@@ -1465,7 +1468,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1465
1468
|
FileUtils.touch 'foo'
|
1466
1469
|
FileUtils.mv 'foo', 'bar', noop: true
|
1467
1470
|
assert File.exist?('foo'), 'does not remove src'
|
1468
|
-
|
1471
|
+
refute File.exist?('bar'), 'does not create target'
|
1469
1472
|
end
|
1470
1473
|
|
1471
1474
|
def test_mv_raises_when_moving_file_onto_directory
|
@@ -1489,11 +1492,11 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1489
1492
|
FileUtils.mv %w(stuff other), 'dir', force: true
|
1490
1493
|
assert File.exist?('stuff'), 'failed move remains where it was'
|
1491
1494
|
assert File.exist?('dir/other'), 'successful one is moved'
|
1492
|
-
|
1495
|
+
refute File.exist?('other'), 'successful one is moved'
|
1493
1496
|
|
1494
1497
|
FileUtils.mv 'stuff', '/this/path/is/not/here', force: true
|
1495
1498
|
assert File.exist?('stuff'), 'failed move remains where it was'
|
1496
|
-
|
1499
|
+
refute File.exist?('/this/path/is/not/here'), 'nothing is created for a failed move'
|
1497
1500
|
end
|
1498
1501
|
|
1499
1502
|
def test_cp_actually_works
|
@@ -1523,7 +1526,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1523
1526
|
def test_cp_fails_on_array_of_files_into_non_directory
|
1524
1527
|
File.open('foo', 'w') { |f| f.write 'footext' }
|
1525
1528
|
|
1526
|
-
exception =
|
1529
|
+
exception = assert_raises(Errno::ENOTDIR) do
|
1527
1530
|
FileUtils.cp(%w(foo), 'baz')
|
1528
1531
|
end
|
1529
1532
|
assert_equal 'Not a directory - baz', exception.to_s
|
@@ -1538,7 +1541,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1538
1541
|
end
|
1539
1542
|
|
1540
1543
|
def test_cp_fails_on_no_source
|
1541
|
-
|
1544
|
+
assert_raises Errno::ENOENT do
|
1542
1545
|
FileUtils.cp('foo', 'baz')
|
1543
1546
|
end
|
1544
1547
|
end
|
@@ -1546,7 +1549,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1546
1549
|
def test_cp_fails_on_directory_copy
|
1547
1550
|
FileUtils.mkdir_p 'baz'
|
1548
1551
|
|
1549
|
-
|
1552
|
+
assert_raises Errno::EISDIR do
|
1550
1553
|
FileUtils.cp('baz', 'bar')
|
1551
1554
|
end
|
1552
1555
|
end
|
@@ -1567,7 +1570,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1567
1570
|
def test_cp_r_should_raise_error_on_missing_file
|
1568
1571
|
# Yes, this error sucks, but it conforms to the original Ruby
|
1569
1572
|
# method.
|
1570
|
-
|
1573
|
+
assert_raises(RuntimeError) do
|
1571
1574
|
FileUtils.cp_r 'blafgag', 'foo'
|
1572
1575
|
end
|
1573
1576
|
end
|
@@ -1642,100 +1645,99 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1642
1645
|
end
|
1643
1646
|
|
1644
1647
|
def test_clone_clones_normal_files
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1648
|
+
act_on_real_fs do
|
1649
|
+
File.open(real_file_sandbox('foo'), 'w') do |f|
|
1650
|
+
f.write 'bar'
|
1651
|
+
end
|
1652
|
+
|
1653
|
+
assert RealFile.file?(real_file_sandbox('foo'))
|
1654
|
+
assert File.file?(real_file_sandbox('foo'))
|
1655
|
+
end
|
1656
|
+
|
1657
|
+
assert RealFile.file?(real_file_sandbox('foo'))
|
1658
|
+
|
1659
|
+
refute File.exist?(real_file_sandbox('foo'))
|
1660
|
+
FakeFS::FileSystem.clone(real_file_sandbox('foo'))
|
1661
|
+
assert_equal 'bar', File.open(real_file_sandbox('foo')) { |f| f.read }
|
1651
1662
|
end
|
1652
1663
|
|
1653
1664
|
def test_clone_clones_directories
|
1654
|
-
act_on_real_fs {
|
1665
|
+
act_on_real_fs { FileUtils.mkdir_p(real_file_sandbox('subdir')) }
|
1655
1666
|
|
1656
|
-
FileSystem.clone(
|
1667
|
+
FakeFS::FileSystem.clone(real_file_sandbox('subdir'))
|
1657
1668
|
|
1658
|
-
assert File.exist?(
|
1659
|
-
assert File.directory?(
|
1660
|
-
ensure
|
1661
|
-
act_on_real_fs { RealFileUtils.rm_rf(here('subdir')) }
|
1669
|
+
assert File.exist?(real_file_sandbox('subdir')), 'subdir was cloned'
|
1670
|
+
assert File.directory?(real_file_sandbox('subdir')), 'subdir is a directory'
|
1662
1671
|
end
|
1663
1672
|
|
1664
1673
|
def test_clone_clones_dot_files_even_hard_to_find_ones
|
1665
|
-
act_on_real_fs {
|
1674
|
+
act_on_real_fs { FileUtils.mkdir_p(real_file_sandbox('subdir/.bar/baz/.quux/foo')) }
|
1666
1675
|
|
1667
|
-
|
1676
|
+
refute File.exist?(real_file_sandbox('subdir'))
|
1668
1677
|
|
1669
|
-
FileSystem.clone(
|
1670
|
-
assert_equal ['.', '..', '.bar'], Dir.entries(
|
1671
|
-
assert_equal ['.', '..', 'foo'], Dir.entries(
|
1672
|
-
ensure
|
1673
|
-
act_on_real_fs { RealFileUtils.rm_rf(here('subdir')) }
|
1678
|
+
FakeFS::FileSystem.clone(real_file_sandbox('subdir'))
|
1679
|
+
assert_equal ['.', '..', '.bar'], Dir.entries(real_file_sandbox('subdir'))
|
1680
|
+
assert_equal ['.', '..', 'foo'], Dir.entries(real_file_sandbox('subdir/.bar/baz/.quux'))
|
1674
1681
|
end
|
1675
1682
|
|
1676
1683
|
def test_dir_glob_on_clone_with_absolute_path
|
1677
|
-
act_on_real_fs {
|
1684
|
+
act_on_real_fs { FileUtils.mkdir_p(real_file_sandbox('subdir/.bar/baz/.quux/foo')) }
|
1678
1685
|
FileUtils.mkdir_p '/path'
|
1679
1686
|
Dir.chdir('/path')
|
1680
|
-
FileSystem.clone(
|
1687
|
+
FakeFS::FileSystem.clone(real_file_sandbox('subdir'), '/foo')
|
1681
1688
|
assert Dir.glob '/foo/*'
|
1682
|
-
ensure
|
1683
|
-
act_on_real_fs { RealFileUtils.rm_rf(here('subdir')) }
|
1684
1689
|
end
|
1685
1690
|
|
1686
1691
|
def test_clone_with_target_specified
|
1687
|
-
act_on_real_fs
|
1692
|
+
act_on_real_fs do
|
1693
|
+
assert FileUtils == RealFileUtils, 'using the real FileUtils in act_on_real_fs'
|
1694
|
+
FileUtils.mkdir_p(real_file_sandbox('subdir/.bar/baz/.quux/foo'))
|
1695
|
+
end
|
1688
1696
|
|
1689
|
-
|
1697
|
+
refute File.exist?(real_file_sandbox('subdir'))
|
1690
1698
|
|
1691
|
-
FileSystem.clone(
|
1692
|
-
|
1693
|
-
assert_equal ['.', '..', '.bar'], Dir.entries(
|
1694
|
-
assert_equal ['.', '..', 'foo'], Dir.entries(
|
1695
|
-
ensure
|
1696
|
-
act_on_real_fs { RealFileUtils.rm_rf(here('subdir')) }
|
1699
|
+
FakeFS::FileSystem.clone(real_file_sandbox('subdir'), real_file_sandbox('subdir2'))
|
1700
|
+
refute File.exist?(real_file_sandbox('subdir'))
|
1701
|
+
assert_equal ['.', '..', '.bar'], Dir.entries(real_file_sandbox('subdir2'))
|
1702
|
+
assert_equal ['.', '..', 'foo'], Dir.entries(real_file_sandbox('subdir2/.bar/baz/.quux'))
|
1697
1703
|
end
|
1698
1704
|
|
1699
1705
|
def test_clone_with_file_symlinks
|
1700
|
-
original =
|
1701
|
-
symlink =
|
1706
|
+
original = real_file_sandbox('subdir/test-file')
|
1707
|
+
symlink = real_file_sandbox('subdir/test-file.txt')
|
1702
1708
|
|
1703
1709
|
act_on_real_fs do
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
assert
|
1710
|
+
FileUtils.mkdir_p(File.dirname(original))
|
1711
|
+
File.open(original, 'w') { |f| f << 'stuff' }
|
1712
|
+
FileUtils.ln_s original, symlink
|
1713
|
+
assert File.symlink?(symlink), 'real symlink is in place'
|
1708
1714
|
end
|
1709
1715
|
|
1710
|
-
|
1716
|
+
refute File.exist?(original), 'file does not already exist'
|
1711
1717
|
|
1712
|
-
FileSystem.clone(File.dirname(original))
|
1718
|
+
FakeFS::FileSystem.clone(File.dirname(original))
|
1713
1719
|
assert File.symlink?(symlink), 'symlinks are cloned as symlinks'
|
1714
1720
|
assert_equal 'stuff', File.read(symlink)
|
1715
|
-
ensure
|
1716
|
-
act_on_real_fs { RealFileUtils.rm_rf File.dirname(original) }
|
1717
1721
|
end
|
1718
1722
|
|
1719
1723
|
def test_clone_with_dir_symlinks
|
1720
|
-
original =
|
1721
|
-
symlink =
|
1724
|
+
original = real_file_sandbox('subdir/dir')
|
1725
|
+
symlink = real_file_sandbox('subdir/dir.link')
|
1722
1726
|
original_file = File.join(original, 'test-file')
|
1723
1727
|
symlink_file = File.join(symlink, 'test-file')
|
1724
1728
|
|
1725
1729
|
act_on_real_fs do
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
assert
|
1730
|
+
FileUtils.mkdir_p(original)
|
1731
|
+
File.open(original_file, 'w') { |f| f << 'stuff' }
|
1732
|
+
FileUtils.ln_s original, symlink
|
1733
|
+
assert File.symlink?(symlink), 'real symlink is in place'
|
1730
1734
|
end
|
1731
1735
|
|
1732
|
-
|
1736
|
+
refute File.exist?(original_file), 'file does not already exist'
|
1733
1737
|
|
1734
|
-
FileSystem.clone(File.dirname(original))
|
1738
|
+
FakeFS::FileSystem.clone(File.dirname(original))
|
1735
1739
|
assert File.symlink?(symlink), 'symlinks are cloned as symlinks'
|
1736
1740
|
assert_equal 'stuff', File.read(symlink_file)
|
1737
|
-
ensure
|
1738
|
-
act_on_real_fs { RealFileUtils.rm_rf File.dirname(original) }
|
1739
1741
|
end
|
1740
1742
|
|
1741
1743
|
def test_putting_a_dot_at_end_copies_the_contents
|
@@ -1794,9 +1796,8 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1794
1796
|
def test_new_directory
|
1795
1797
|
FileUtils.mkdir_p('/this/path/should/be/here')
|
1796
1798
|
|
1797
|
-
|
1798
|
-
|
1799
|
-
end
|
1799
|
+
# nothing raised
|
1800
|
+
Dir.new('/this/path/should/be/here')
|
1800
1801
|
end
|
1801
1802
|
|
1802
1803
|
def test_new_directory_does_not_work_if_dir_path_cannot_be_found
|
@@ -1909,19 +1910,19 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1909
1910
|
dir = Dir.new('/this/path/should/be/here')
|
1910
1911
|
|
1911
1912
|
d = dir.read
|
1912
|
-
|
1913
|
+
refute_nil d
|
1913
1914
|
d = dir.read
|
1914
|
-
|
1915
|
+
refute_nil d
|
1915
1916
|
d = dir.read
|
1916
|
-
|
1917
|
+
refute_nil d
|
1917
1918
|
d = dir.read
|
1918
|
-
|
1919
|
+
refute_nil d
|
1919
1920
|
d = dir.read
|
1920
|
-
|
1921
|
+
refute_nil d
|
1921
1922
|
d = dir.read
|
1922
|
-
|
1923
|
+
refute_nil d
|
1923
1924
|
d = dir.read
|
1924
|
-
|
1925
|
+
refute_nil d
|
1925
1926
|
d = dir.read
|
1926
1927
|
assert_nil d
|
1927
1928
|
end
|
@@ -2085,7 +2086,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2085
2086
|
|
2086
2087
|
def test_directory_mkdir_relative
|
2087
2088
|
FileUtils.mkdir_p('/new/root')
|
2088
|
-
FileSystem.chdir('/new/root')
|
2089
|
+
FakeFS::FileSystem.chdir('/new/root')
|
2089
2090
|
Dir.mkdir('path')
|
2090
2091
|
assert File.exist?('/new/root/path')
|
2091
2092
|
end
|
@@ -2260,7 +2261,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2260
2261
|
|
2261
2262
|
File.delete('/foo')
|
2262
2263
|
|
2263
|
-
|
2264
|
+
refute File.exist?('/foo')
|
2264
2265
|
end
|
2265
2266
|
|
2266
2267
|
def test_can_delete_multiple_files_with_delete
|
@@ -2269,8 +2270,8 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2269
2270
|
|
2270
2271
|
File.delete('/foo', '/bar')
|
2271
2272
|
|
2272
|
-
|
2273
|
-
|
2273
|
+
refute File.exist?('/foo')
|
2274
|
+
refute File.exist?('/bar')
|
2274
2275
|
end
|
2275
2276
|
|
2276
2277
|
def test_delete_returns_zero_when_no_filename_given
|
@@ -2319,7 +2320,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2319
2320
|
File.unlink('/bar')
|
2320
2321
|
|
2321
2322
|
assert File.exist?('/foo')
|
2322
|
-
|
2323
|
+
refute File.exist?('/bar')
|
2323
2324
|
end
|
2324
2325
|
|
2325
2326
|
def test_delete_works_with_symlink_source
|
@@ -2328,7 +2329,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2328
2329
|
|
2329
2330
|
File.unlink('/foo')
|
2330
2331
|
|
2331
|
-
|
2332
|
+
refute File.exist?('/foo')
|
2332
2333
|
end
|
2333
2334
|
|
2334
2335
|
def test_file_seek_returns_0
|
@@ -2389,7 +2390,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2389
2390
|
assert FileTest.exist?('/path/to/')
|
2390
2391
|
|
2391
2392
|
FileUtils.rmdir('/path/to/dir')
|
2392
|
-
|
2393
|
+
refute FileTest.exist?('/path/to/dir')
|
2393
2394
|
end
|
2394
2395
|
|
2395
2396
|
def test_filetest_directory_returns_correct_values
|
@@ -2397,7 +2398,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2397
2398
|
assert FileTest.directory?('/path/to/somedir')
|
2398
2399
|
|
2399
2400
|
FileUtils.rm_r '/path/to/somedir'
|
2400
|
-
|
2401
|
+
refute FileTest.directory?('/path/to/somedir')
|
2401
2402
|
end
|
2402
2403
|
|
2403
2404
|
def test_filetest_file_returns_correct_values
|
@@ -2408,14 +2409,14 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2408
2409
|
assert FileTest.file?(path)
|
2409
2410
|
|
2410
2411
|
FileUtils.rm path
|
2411
|
-
|
2412
|
+
refute FileTest.file?(path)
|
2412
2413
|
|
2413
2414
|
FileUtils.mkdir_p '/path/to/somedir'
|
2414
|
-
|
2415
|
+
refute FileTest.file?('/path/to/somedir')
|
2415
2416
|
end
|
2416
2417
|
|
2417
2418
|
def test_filetest_readable_returns_correct_values
|
2418
|
-
|
2419
|
+
refute FileTest.readable?('not-here.txt'), 'missing files are not readable'
|
2419
2420
|
|
2420
2421
|
FileUtils.touch 'here.txt'
|
2421
2422
|
assert FileTest.readable?('here.txt'), 'existing files are readable'
|
@@ -2425,7 +2426,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2425
2426
|
end
|
2426
2427
|
|
2427
2428
|
def test_filetest_writable_returns_correct_values
|
2428
|
-
|
2429
|
+
refute FileTest.writable?('not-here.txt'), 'missing files are not writable'
|
2429
2430
|
|
2430
2431
|
FileUtils.touch 'here.txt'
|
2431
2432
|
assert FileTest.writable?('here.txt'), 'existing files are writable'
|
@@ -2445,7 +2446,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2445
2446
|
tmpdir = t
|
2446
2447
|
assert File.directory?(t)
|
2447
2448
|
end
|
2448
|
-
|
2449
|
+
refute File.directory?(tmpdir)
|
2449
2450
|
end
|
2450
2451
|
|
2451
2452
|
def test_activating_returns_true
|
@@ -2567,11 +2568,11 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2567
2568
|
different1 = File.new('d1', 'w')
|
2568
2569
|
different2 = File.new('d2', 'w')
|
2569
2570
|
|
2570
|
-
FileSystem.find('s1').mtime = a_time
|
2571
|
-
FileSystem.find('s2').mtime = a_time
|
2571
|
+
FakeFS::FileSystem.find('s1').mtime = a_time
|
2572
|
+
FakeFS::FileSystem.find('s2').mtime = a_time
|
2572
2573
|
|
2573
|
-
FileSystem.find('d1').mtime = a_time
|
2574
|
-
FileSystem.find('d2').mtime = a_time + 1
|
2574
|
+
FakeFS::FileSystem.find('d1').mtime = a_time
|
2575
|
+
FakeFS::FileSystem.find('d2').mtime = a_time + 1
|
2575
2576
|
|
2576
2577
|
assert same1.mtime == same2.mtime
|
2577
2578
|
assert different1.mtime != different2.mtime
|
@@ -2593,10 +2594,6 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2593
2594
|
assert_equal File.binread('testfile', 20, 10), "ne one\nThis is line "
|
2594
2595
|
end
|
2595
2596
|
|
2596
|
-
def here(fname)
|
2597
|
-
RealFile.expand_path(File.join(RealFile.dirname(__FILE__), fname))
|
2598
|
-
end
|
2599
|
-
|
2600
2597
|
def test_file_utils_compare_file
|
2601
2598
|
file1 = 'file1.txt'
|
2602
2599
|
file2 = 'file2.txt'
|
@@ -2653,9 +2650,8 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2653
2650
|
def test_fdatasync
|
2654
2651
|
File.open('foo', 'w') do |f|
|
2655
2652
|
f << 'Yada Yada'
|
2656
|
-
|
2657
|
-
|
2658
|
-
end
|
2653
|
+
# nothing raised
|
2654
|
+
f.fdatasync
|
2659
2655
|
end
|
2660
2656
|
end
|
2661
2657
|
|
@@ -2677,9 +2673,8 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2677
2673
|
if RUBY_VERSION >= '1.9.3'
|
2678
2674
|
def test_advise
|
2679
2675
|
File.open('foo', 'w') do |f|
|
2680
|
-
|
2681
|
-
|
2682
|
-
end
|
2676
|
+
# nothing raised
|
2677
|
+
f.advise(:normal, 0, 0)
|
2683
2678
|
end
|
2684
2679
|
end
|
2685
2680
|
|
@@ -2745,4 +2740,22 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2745
2740
|
assert_equal "\x00\x00\x00\x03\x00\x03\x00\xA3\x00\x00\x00y\x00\x00\x00\x00\x00".force_encoding('ASCII-8BIT'), File.binread('foo')
|
2746
2741
|
end
|
2747
2742
|
end
|
2743
|
+
|
2744
|
+
if RUBY_VERSION >= '2.2.0'
|
2745
|
+
def test_raises_error_on_birthtime_if_file_does_not_exist
|
2746
|
+
assert_raises Errno::ENOENT do
|
2747
|
+
File.birthtime('file.txt')
|
2748
|
+
end
|
2749
|
+
end
|
2750
|
+
|
2751
|
+
def test_can_return_birthtime_on_existing_file
|
2752
|
+
File.open('foo', 'w') { |f| f << 'some content' }
|
2753
|
+
assert File.birthtime('foo').is_a?(Time)
|
2754
|
+
end
|
2755
|
+
|
2756
|
+
def test_file_birthtime_is_equal_to_file_stat_birthtime
|
2757
|
+
File.open('foo', 'w') { |f| f << 'some content' }
|
2758
|
+
assert_equal File.stat('foo').birthtime, File.birthtime('foo')
|
2759
|
+
end
|
2760
|
+
end
|
2748
2761
|
end
|