fakefs 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +50 -0
- data/.travis.yml +0 -1
- data/Rakefile +16 -9
- data/fakefs.gemspec +1 -0
- data/lib/fakefs/base.rb +6 -5
- data/lib/fakefs/dir.rb +55 -45
- data/lib/fakefs/fake/dir.rb +5 -3
- data/lib/fakefs/fake/file.rb +9 -4
- data/lib/fakefs/fake/symlink.rb +2 -1
- data/lib/fakefs/file.rb +98 -103
- data/lib/fakefs/file_system.rb +50 -33
- data/lib/fakefs/file_test.rb +1 -0
- data/lib/fakefs/fileutils.rb +72 -71
- data/lib/fakefs/kernel.rb +8 -7
- data/lib/fakefs/pathname.rb +356 -202
- data/lib/fakefs/safe.rb +1 -1
- data/lib/fakefs/spec_helpers.rb +19 -11
- data/lib/fakefs/version.rb +2 -1
- data/spec/fakefs/fakefs_bug_ruby_2.1.0-preview2_spec.rb +2 -2
- data/spec/fakefs/spec_helpers_spec.rb +24 -23
- data/test/dir/tempfile_test.rb +1 -0
- data/test/fake/file/join_test.rb +4 -3
- data/test/fake/file/lstat_test.rb +22 -21
- data/test/fake/file/stat_test.rb +12 -11
- data/test/fake/file/sysseek_test.rb +15 -14
- data/test/fake/file/syswrite_test.rb +25 -24
- data/test/fake/file_test.rb +12 -11
- data/test/fake/symlink_test.rb +18 -10
- data/test/fakefs_test.rb +543 -542
- data/test/file/stat_test.rb +45 -41
- data/test/kernel_test.rb +5 -8
- data/test/safe_test.rb +9 -7
- data/test/test_helper.rb +2 -1
- data/test/verify.rb +6 -3
- metadata +28 -14
data/test/file/stat_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
+
# File stat test class
|
3
4
|
class FileStatTest < Test::Unit::TestCase
|
4
5
|
include FakeFS
|
5
6
|
|
@@ -25,66 +26,66 @@ class FileStatTest < Test::Unit::TestCase
|
|
25
26
|
|
26
27
|
def test_file_stat_init_with_non_existent_file
|
27
28
|
assert_raises(Errno::ENOENT) do
|
28
|
-
File::Stat.new(
|
29
|
+
File::Stat.new('/foo')
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
def test_file_should_be_true_when_file
|
33
|
-
touch(
|
34
|
-
assert File::Stat.new(
|
34
|
+
touch('/foo')
|
35
|
+
assert File::Stat.new('/foo').file?
|
35
36
|
end
|
36
37
|
|
37
38
|
def test_symlink_should_be_true_when_symlink
|
38
|
-
touch(
|
39
|
-
ln_s(
|
39
|
+
touch('/foo')
|
40
|
+
ln_s('/foo', '/bar')
|
40
41
|
|
41
|
-
assert File::Stat.new(
|
42
|
-
assert File::Stat.new(
|
42
|
+
assert File::Stat.new('/bar').symlink?
|
43
|
+
assert File::Stat.new('/bar').ftype == 'link'
|
43
44
|
end
|
44
45
|
|
45
46
|
def test_symlink_should_be_false_when_not_a_symlink
|
46
|
-
FileUtils.touch(
|
47
|
+
FileUtils.touch('/foo')
|
47
48
|
|
48
|
-
assert !File::Stat.new(
|
49
|
-
assert File::Stat.new(
|
49
|
+
assert !File::Stat.new('/foo').symlink?
|
50
|
+
assert File::Stat.new('/foo').ftype == 'file'
|
50
51
|
end
|
51
52
|
|
52
53
|
def test_should_return_false_for_directory_when_not_a_directory
|
53
|
-
FileUtils.touch(
|
54
|
+
FileUtils.touch('/foo')
|
54
55
|
|
55
|
-
assert !File::Stat.new(
|
56
|
-
assert File::Stat.new(
|
56
|
+
assert !File::Stat.new('/foo').directory?
|
57
|
+
assert File::Stat.new('/foo').ftype == 'file'
|
57
58
|
end
|
58
59
|
|
59
60
|
def test_should_return_true_for_directory_when_a_directory
|
60
|
-
mkdir
|
61
|
+
mkdir '/foo'
|
61
62
|
|
62
|
-
assert File::Stat.new(
|
63
|
-
assert File::Stat.new(
|
63
|
+
assert File::Stat.new('/foo').directory?
|
64
|
+
assert File::Stat.new('/foo').ftype == 'directory'
|
64
65
|
end
|
65
66
|
|
66
67
|
def test_writable_is_true
|
67
|
-
touch(
|
68
|
+
touch('/foo')
|
68
69
|
|
69
|
-
assert File::Stat.new(
|
70
|
+
assert File::Stat.new('/foo').writable?
|
70
71
|
end
|
71
72
|
|
72
73
|
def test_readable_is_true
|
73
|
-
touch(
|
74
|
+
touch('/foo')
|
74
75
|
|
75
|
-
assert File::Stat.new(
|
76
|
+
assert File::Stat.new('/foo').readable?
|
76
77
|
end
|
77
78
|
|
78
79
|
def test_one_file_has_hard_link
|
79
|
-
touch
|
80
|
-
assert_equal 1, File.stat(
|
80
|
+
touch 'testfile'
|
81
|
+
assert_equal 1, File.stat('testfile').nlink
|
81
82
|
end
|
82
83
|
|
83
84
|
def test_two_hard_links_show_nlinks_as_two
|
84
|
-
touch
|
85
|
-
ln
|
85
|
+
touch 'testfile'
|
86
|
+
ln 'testfile', 'testfile.bak'
|
86
87
|
|
87
|
-
assert_equal 2, File.stat(
|
88
|
+
assert_equal 2, File.stat('testfile').nlink
|
88
89
|
end
|
89
90
|
|
90
91
|
def test_file_size
|
@@ -94,38 +95,41 @@ class FileStatTest < Test::Unit::TestCase
|
|
94
95
|
|
95
96
|
def test_file_zero?
|
96
97
|
File.open('testfile', 'w') { |f| f << 'test' }
|
97
|
-
assert !File.stat('testfile').zero?,
|
98
|
+
assert !File.stat('testfile').zero?, 'testfile has size 4, not zero'
|
98
99
|
|
99
100
|
FileUtils.touch('testfile2')
|
100
|
-
assert File.stat('testfile2').zero?,
|
101
|
+
assert File.stat('testfile2').zero?, 'testfile2 has size 0, but stat lied'
|
101
102
|
end
|
102
103
|
|
103
104
|
def test_touch_modifies_mtime
|
104
|
-
FileUtils.touch(
|
105
|
-
mtime = File.mtime(
|
105
|
+
FileUtils.touch('/foo')
|
106
|
+
mtime = File.mtime('/foo')
|
106
107
|
|
107
|
-
FileUtils.touch(
|
108
|
-
assert File.mtime(
|
108
|
+
FileUtils.touch('/foo')
|
109
|
+
assert File.mtime('/foo') > mtime
|
109
110
|
end
|
110
111
|
|
111
112
|
def test_writing_to_file_modifies_mtime
|
112
|
-
FileUtils.touch(
|
113
|
-
mtime = File.mtime(
|
113
|
+
FileUtils.touch('/foo')
|
114
|
+
mtime = File.mtime('/foo')
|
114
115
|
|
115
116
|
File.open('/foo', 'w') { |f| f << 'test' }
|
116
|
-
assert File.mtime(
|
117
|
+
assert File.mtime('/foo') > mtime
|
117
118
|
end
|
118
119
|
|
119
120
|
def test_responds_to_world_writable
|
120
|
-
FileUtils.touch(
|
121
|
-
|
122
|
-
|
121
|
+
FileUtils.touch('/foo')
|
122
|
+
assert File::Stat.new('/foo').world_writable? == 0777
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_responds_to_sticky
|
126
|
+
FileUtils.touch('/foo')
|
127
|
+
assert !File::Stat.new('/foo').sticky?
|
123
128
|
end
|
124
129
|
|
125
130
|
def test_responds_to_world_readable
|
126
|
-
FileUtils.touch(
|
127
|
-
|
128
|
-
assert File::Stat.new("/foo").world_readable? == 0777, "#{File::Stat.new("/foo").world_readable?}"
|
131
|
+
FileUtils.touch('/foo')
|
132
|
+
assert File::Stat.new('/foo').world_readable? == 0777, "#{File::Stat.new('/foo').world_readable?}"
|
129
133
|
end
|
130
134
|
|
131
135
|
def test_responds_to_world_readable
|
data/test/kernel_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
+
# Kernel test class
|
3
4
|
class KernelTest < Test::Unit::TestCase
|
4
5
|
include FakeFS
|
5
6
|
def setup
|
@@ -25,8 +26,8 @@ class KernelTest < Test::Unit::TestCase
|
|
25
26
|
def test_fake_kernel_can_create_new_file
|
26
27
|
FakeFS do
|
27
28
|
FileUtils.mkdir_p '/path/to/'
|
28
|
-
open('/path/to/file',
|
29
|
-
f <<
|
29
|
+
open('/path/to/file', 'w') do |f|
|
30
|
+
f << 'test'
|
30
31
|
end
|
31
32
|
assert_kind_of FakeFile, FileSystem.fs['path']['to']['file']
|
32
33
|
end
|
@@ -38,10 +39,8 @@ class KernelTest < Test::Unit::TestCase
|
|
38
39
|
File.open('/tmp/a', 'w+') { |f| f.puts 'test' }
|
39
40
|
|
40
41
|
begin
|
41
|
-
|
42
|
-
rescue
|
43
|
-
puts e
|
44
|
-
puts e.backtrace
|
42
|
+
open('/tmp/a').read
|
43
|
+
rescue => e
|
45
44
|
raise e
|
46
45
|
end
|
47
46
|
end
|
@@ -51,6 +50,4 @@ class KernelTest < Test::Unit::TestCase
|
|
51
50
|
out = open("|echo 'foo'")
|
52
51
|
assert_equal "foo\n", out.gets
|
53
52
|
end
|
54
|
-
|
55
53
|
end
|
56
|
-
|
data/test/safe_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
+
# FakeFS safe test class
|
3
4
|
class FakeFSSafeTest < Test::Unit::TestCase
|
4
5
|
def setup
|
5
6
|
FakeFS.deactivate!
|
@@ -22,20 +23,20 @@ class FakeFSSafeTest < Test::Unit::TestCase
|
|
22
23
|
path = 'file.txt'
|
23
24
|
|
24
25
|
FakeFS do
|
25
|
-
File.open(path, 'w') { |f| f.write
|
26
|
-
assert File.
|
26
|
+
File.open(path, 'w') { |f| f.write 'Yatta!' }
|
27
|
+
assert File.exist?(path)
|
27
28
|
end
|
28
29
|
|
29
|
-
assert !
|
30
|
+
assert !File.exist?(path)
|
30
31
|
end
|
31
32
|
|
32
33
|
def test_FakeFS_method_returns_value_of_yield
|
33
34
|
result = FakeFS do
|
34
|
-
File.open('myfile.txt', 'w') { |f| f.write
|
35
|
+
File.open('myfile.txt', 'w') { |f| f.write 'Yatta!' }
|
35
36
|
File.read('myfile.txt')
|
36
37
|
end
|
37
38
|
|
38
|
-
assert_equal result,
|
39
|
+
assert_equal result, 'Yatta!'
|
39
40
|
end
|
40
41
|
|
41
42
|
def test_FakeFS_method_does_not_deactivate_FakeFS_if_already_activated
|
@@ -72,9 +73,10 @@ class FakeFSSafeTest < Test::Unit::TestCase
|
|
72
73
|
def test_FakeFS_method_deactivates_FakeFS_when_block_raises_exception
|
73
74
|
begin
|
74
75
|
FakeFS do
|
75
|
-
|
76
|
+
fail 'boom!'
|
76
77
|
end
|
77
78
|
rescue
|
79
|
+
'Nothing to do'
|
78
80
|
end
|
79
81
|
|
80
82
|
assert !FakeFS.activated?
|
data/test/test_helper.rb
CHANGED
data/test/verify.rb
CHANGED
@@ -4,8 +4,9 @@
|
|
4
4
|
#
|
5
5
|
# $ RUBYLIB=test ruby test/verify.rb | grep "not implemented"
|
6
6
|
|
7
|
-
require
|
7
|
+
require 'test_helper'
|
8
8
|
|
9
|
+
# FakeFs verifier test class
|
9
10
|
class FakeFSVerifierTest < Test::Unit::TestCase
|
10
11
|
class_mapping = {
|
11
12
|
RealFile => FakeFS::File,
|
@@ -18,13 +19,15 @@ class FakeFSVerifierTest < Test::Unit::TestCase
|
|
18
19
|
class_mapping.each do |real_class, fake_class|
|
19
20
|
real_class.methods.each do |method|
|
20
21
|
define_method "test #{method} class method" do
|
21
|
-
assert fake_class.respond_to?(method),
|
22
|
+
assert fake_class.respond_to?(method),
|
23
|
+
"#{fake_class}.#{method} not implemented"
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
real_class.instance_methods.each do |method|
|
26
28
|
define_method("test #{method} instance method") do
|
27
|
-
assert fake_class.instance_methods.include?(method),
|
29
|
+
assert fake_class.instance_methods.include?(method),
|
30
|
+
"#{fake_class}##{method} not implemented"
|
28
31
|
end
|
29
32
|
end
|
30
33
|
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.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -18,44 +18,58 @@ dependencies:
|
|
18
18
|
name: bundler
|
19
19
|
requirement: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- - ~>
|
21
|
+
- - "~>"
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: '1.3'
|
24
24
|
type: :development
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- - ~>
|
28
|
+
- - "~>"
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '1.3'
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: rake
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
|
-
- - ~>
|
35
|
+
- - "~>"
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '10.1'
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- - ~>
|
42
|
+
- - "~>"
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '10.1'
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: rspec
|
47
47
|
requirement: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
|
-
- - ~>
|
49
|
+
- - "~>"
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '2.14'
|
52
52
|
type: :development
|
53
53
|
prerelease: false
|
54
54
|
version_requirements: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
|
-
- - ~>
|
56
|
+
- - "~>"
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '2.14'
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rubocop
|
61
|
+
requirement: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - "~>"
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0.25'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0.25'
|
59
73
|
description: A fake filesystem. Use it in your tests.
|
60
74
|
email:
|
61
75
|
- chris@ozmm.org
|
@@ -63,10 +77,11 @@ executables: []
|
|
63
77
|
extensions: []
|
64
78
|
extra_rdoc_files: []
|
65
79
|
files:
|
66
|
-
- .autotest
|
67
|
-
- .gitignore
|
68
|
-
- .rspec
|
69
|
-
- .
|
80
|
+
- ".autotest"
|
81
|
+
- ".gitignore"
|
82
|
+
- ".rspec"
|
83
|
+
- ".rubocop.yml"
|
84
|
+
- ".travis.yml"
|
70
85
|
- CONTRIBUTORS
|
71
86
|
- Gemfile
|
72
87
|
- LICENSE
|
@@ -116,12 +131,12 @@ require_paths:
|
|
116
131
|
- lib
|
117
132
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
133
|
requirements:
|
119
|
-
- -
|
134
|
+
- - ">="
|
120
135
|
- !ruby/object:Gem::Version
|
121
136
|
version: '0'
|
122
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
138
|
requirements:
|
124
|
-
- -
|
139
|
+
- - ">="
|
125
140
|
- !ruby/object:Gem::Version
|
126
141
|
version: '0'
|
127
142
|
requirements: []
|
@@ -149,4 +164,3 @@ test_files:
|
|
149
164
|
- test/safe_test.rb
|
150
165
|
- test/test_helper.rb
|
151
166
|
- test/verify.rb
|
152
|
-
has_rdoc:
|