fakefs 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +9 -9
- data/lib/fakefs/dir.rb +17 -12
- data/lib/fakefs/fake/file.rb +1 -1
- data/lib/fakefs/file.rb +18 -0
- data/lib/fakefs/fileutils.rb +22 -5
- data/lib/fakefs/globber.rb +1 -0
- data/lib/fakefs/pathname.rb +6 -3
- data/lib/fakefs/version.rb +1 -1
- metadata +19 -55
- data/.autotest +0 -5
- data/.gitignore +0 -12
- data/.rspec +0 -1
- data/.rubocop.yml +0 -54
- data/.travis.yml +0 -15
- data/CONTRIBUTORS +0 -97
- data/Gemfile +0 -3
- data/Rakefile +0 -62
- data/etc/git-rank-contributors +0 -57
- data/fakefs.gemspec +0 -27
- data/spec/fakefs/fakefs_bug_ruby_2.1.0-preview2_spec.rb +0 -18
- data/spec/fakefs/spec_helpers_spec.rb +0 -102
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -3
- data/test/dir/tempfile_test.rb +0 -21
- data/test/fake/file/join_test.rb +0 -20
- data/test/fake/file/lstat_test.rb +0 -60
- data/test/fake/file/stat_test.rb +0 -40
- data/test/fake/file/sysseek_test.rb +0 -45
- data/test/fake/file/syswrite_test.rb +0 -63
- data/test/fake/file_test.rb +0 -112
- data/test/fake/symlink_test.rb +0 -33
- data/test/fakefs_test.rb +0 -2769
- data/test/file/stat_test.rb +0 -158
- data/test/globber_test.rb +0 -28
- data/test/kernel_test.rb +0 -57
- data/test/pathname_test.rb +0 -75
- data/test/safe_test.rb +0 -84
- data/test/test_helper.rb +0 -33
- data/test/verify.rb +0 -34
data/test/file/stat_test.rb
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# File stat test class
|
4
|
-
class FileStatTest < Minitest::Test
|
5
|
-
include FakeFS
|
6
|
-
|
7
|
-
def setup
|
8
|
-
FileSystem.clear
|
9
|
-
end
|
10
|
-
|
11
|
-
def touch(*args)
|
12
|
-
FileUtils.touch(*args)
|
13
|
-
end
|
14
|
-
|
15
|
-
def ln_s(*args)
|
16
|
-
FileUtils.ln_s(*args)
|
17
|
-
end
|
18
|
-
|
19
|
-
def mkdir(*args)
|
20
|
-
Dir.mkdir(*args)
|
21
|
-
end
|
22
|
-
|
23
|
-
def ln(*args)
|
24
|
-
File.link(*args)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_file_stat_init_with_non_existent_file
|
28
|
-
assert_raises(Errno::ENOENT) do
|
29
|
-
File::Stat.new('/foo')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_file_should_be_true_when_file
|
34
|
-
touch('/foo')
|
35
|
-
assert File::Stat.new('/foo').file?
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_symlink_should_be_true_when_symlink
|
39
|
-
touch('/foo')
|
40
|
-
ln_s('/foo', '/bar')
|
41
|
-
|
42
|
-
assert File::Stat.new('/bar').symlink?
|
43
|
-
assert File::Stat.new('/bar').ftype == 'link'
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_symlink_should_be_false_when_not_a_symlink
|
47
|
-
FileUtils.touch('/foo')
|
48
|
-
|
49
|
-
refute File::Stat.new('/foo').symlink?
|
50
|
-
assert File::Stat.new('/foo').ftype == 'file'
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_should_return_false_for_directory_when_not_a_directory
|
54
|
-
FileUtils.touch('/foo')
|
55
|
-
|
56
|
-
refute File::Stat.new('/foo').directory?
|
57
|
-
assert File::Stat.new('/foo').ftype == 'file'
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_return_true_for_directory_when_a_directory
|
61
|
-
mkdir '/foo'
|
62
|
-
|
63
|
-
assert File::Stat.new('/foo').directory?
|
64
|
-
assert File::Stat.new('/foo').ftype == 'directory'
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_writable_is_true
|
68
|
-
touch('/foo')
|
69
|
-
|
70
|
-
assert File::Stat.new('/foo').writable?
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_readable_is_true
|
74
|
-
touch('/foo')
|
75
|
-
|
76
|
-
assert File::Stat.new('/foo').readable?
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_one_file_has_hard_link
|
80
|
-
touch 'testfile'
|
81
|
-
assert_equal 1, File.stat('testfile').nlink
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_two_hard_links_show_nlinks_as_two
|
85
|
-
touch 'testfile'
|
86
|
-
ln 'testfile', 'testfile.bak'
|
87
|
-
|
88
|
-
assert_equal 2, File.stat('testfile').nlink
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_file_size
|
92
|
-
File.open('testfile', 'w') { |f| f << 'test' }
|
93
|
-
assert_equal 4, File.stat('testfile').size
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_file_zero?
|
97
|
-
File.open('testfile', 'w') { |f| f << 'test' }
|
98
|
-
refute File.stat('testfile').zero?, 'testfile has size 4, not zero'
|
99
|
-
|
100
|
-
FileUtils.touch('testfile2')
|
101
|
-
assert File.stat('testfile2').zero?, 'testfile2 has size 0, but stat lied'
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_touch_modifies_mtime
|
105
|
-
FileUtils.touch('/foo')
|
106
|
-
mtime = File.mtime('/foo')
|
107
|
-
|
108
|
-
FileUtils.touch('/foo')
|
109
|
-
assert File.mtime('/foo') > mtime
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_writing_to_file_modifies_mtime
|
113
|
-
FileUtils.touch('/foo')
|
114
|
-
mtime = File.mtime('/foo')
|
115
|
-
|
116
|
-
File.open('/foo', 'w') { |f| f << 'test' }
|
117
|
-
assert File.mtime('/foo') > mtime
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_responds_to_world_writable
|
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
|
-
refute File::Stat.new('/foo').sticky?
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_responds_to_world_readable
|
131
|
-
FileUtils.touch('/foo')
|
132
|
-
assert File::Stat.new('/foo').world_readable? == 0777, "#{File::Stat.new('/foo').world_readable?}"
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_can_open_tempfile
|
136
|
-
FakeFS do
|
137
|
-
require 'tempfile'
|
138
|
-
FileUtils.mkdir_p('/tmp')
|
139
|
-
::Tempfile.open('test', '/tmp')
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_responds_to_realpath_only_on_1_9
|
144
|
-
if RUBY_VERSION > '1.9'
|
145
|
-
assert File.respond_to?(:realpath)
|
146
|
-
else
|
147
|
-
refute File.respond_to?(:realpath)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_responds_to_realdirpath_only_on_1_9_2_and_greater
|
152
|
-
if RUBY_VERSION >= '1.9.2'
|
153
|
-
assert File.respond_to?(:realdirpath)
|
154
|
-
else
|
155
|
-
refute File.respond_to?(:realdirpath)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
data/test/globber_test.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Globber test class
|
4
|
-
class GlobberTest < Minitest::Test
|
5
|
-
def test_expand_without_brace_groups_returns_single_entry
|
6
|
-
assert_equal ['*.rb'], FakeFS::Globber.expand('*.rb')
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_expand_with_brace_group_with_one_entry_returns_single_entry
|
10
|
-
assert_equal ['abc'], FakeFS::Globber.expand('{abc}')
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_expand_with_brace_group_with_multiple_entries_returns_all_entries
|
14
|
-
assert_equal %w(a b c), FakeFS::Globber.expand('{a,b,c}')
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_expand_with_brace_group_with_nested_entries_expands_only_first_level
|
18
|
-
assert_equal ['a', 'b', '{c,d}'], FakeFS::Globber.expand('{a,b,{c,d}}')
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_path_components_with_no_globbing_splits_on_path_separator
|
22
|
-
assert_equal %w(a b c), FakeFS::Globber.path_components('/a/b/c')
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_path_components_with_path_separator_inside_brace_group
|
26
|
-
assert_equal ['a', '{b,c/d}', 'e'], FakeFS::Globber.path_components('/a/{b,c/d}/e')
|
27
|
-
end
|
28
|
-
end
|
data/test/kernel_test.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Kernel test class
|
4
|
-
class KernelTest < Minitest::Test
|
5
|
-
include FakeFS
|
6
|
-
def setup
|
7
|
-
FakeFS.deactivate!
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
FakeFS.activate!
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_can_exec_normally
|
15
|
-
out = open("|echo 'foo'")
|
16
|
-
assert_equal "foo\n", out.gets
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_fake_kernel_can_create_subprocesses
|
20
|
-
FakeFS do
|
21
|
-
out = open("|echo 'foo'")
|
22
|
-
assert_equal "foo\n", out.gets
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_fake_kernel_can_create_new_file
|
27
|
-
FakeFS do
|
28
|
-
FileUtils.mkdir_p '/path/to/'
|
29
|
-
open('/path/to/file', 'w') do |f|
|
30
|
-
f << 'test'
|
31
|
-
end
|
32
|
-
assert_kind_of FakeFile, FileSystem.fs['path']['to']['file']
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_fake_kernel_can_do_stuff
|
37
|
-
FakeFS do
|
38
|
-
FileUtils.mkdir_p('/tmp')
|
39
|
-
File.open('/tmp/a', 'w+') { |f| f.puts 'test' }
|
40
|
-
|
41
|
-
begin
|
42
|
-
open('/tmp/a').read
|
43
|
-
rescue => e
|
44
|
-
raise e
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_kernel_open_remains_private
|
50
|
-
refute 'foo'.respond_to?(:open), 'String#open should be private'
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_can_exec_normally2
|
54
|
-
out = open("|echo 'foo'")
|
55
|
-
assert_equal "foo\n", out.gets
|
56
|
-
end
|
57
|
-
end
|
data/test/pathname_test.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Fake Pathname test class
|
4
|
-
class FakePathnameTest < Minitest::Test
|
5
|
-
include FakeFS
|
6
|
-
|
7
|
-
def setup
|
8
|
-
FakeFS.activate!
|
9
|
-
FileSystem.clear
|
10
|
-
|
11
|
-
@path = 'foo'
|
12
|
-
@pathname = Pathname.new(@path)
|
13
|
-
end
|
14
|
-
|
15
|
-
def teardown
|
16
|
-
FakeFS.deactivate!
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_filetest_exists_returns_correct_value
|
20
|
-
refute @pathname.exist?
|
21
|
-
|
22
|
-
File.write(@path, '')
|
23
|
-
|
24
|
-
assert @pathname.exist?
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_io_each_line_with_block_yields_lines
|
28
|
-
File.write(@path, "one\ntwo\nthree\n")
|
29
|
-
|
30
|
-
yielded = []
|
31
|
-
@pathname.each_line { |line| yielded << line }
|
32
|
-
|
33
|
-
assert_equal yielded, ["one\n", "two\n", "three\n"]
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_io_each_line_without_block_returns_enumerator
|
37
|
-
File.write(@path, "one\ntwo\nthree\n")
|
38
|
-
|
39
|
-
assert @pathname.each_line.is_a?(Enumerator)
|
40
|
-
assert_equal %w(o t t), @pathname.each_line.map { |l| l[0] }
|
41
|
-
assert_equal ["one\ntwo\nth", "ree\n"], @pathname.each_line('th').to_a
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_io_read_returns_file_contents
|
45
|
-
File.write(@path, "some\ncontent")
|
46
|
-
|
47
|
-
assert_equal "some\ncontent", @pathname.read
|
48
|
-
assert_equal "some\nc", @pathname.read(6)
|
49
|
-
assert_equal "e\nco", @pathname.read(4, 3)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_io_binread_returns_file_contents
|
53
|
-
File.write(@path, "some\ncontent")
|
54
|
-
|
55
|
-
assert_equal "some\ncontent", @pathname.binread
|
56
|
-
assert_equal "some\nc", @pathname.binread(6)
|
57
|
-
assert_equal "e\nco", @pathname.binread(4, 3)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_io_binread_reads_contents_as_binary
|
61
|
-
File.write(@path, "some\ncontent")
|
62
|
-
|
63
|
-
assert_equal 'ASCII-8BIT', @pathname.binread.encoding.name
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_io_readlines_returns_array_of_lines
|
67
|
-
File.write(@path, "one\ntwo\nthree\n")
|
68
|
-
|
69
|
-
assert_equal ["one\n", "two\n", "three\n"], @pathname.readlines
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_io_sysopen_is_unsupported
|
73
|
-
assert_raises(NotImplementedError) { @pathname.sysopen }
|
74
|
-
end
|
75
|
-
end
|
data/test/safe_test.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# FakeFS safe test class
|
4
|
-
class FakeFSSafeTest < Minitest::Test
|
5
|
-
def setup
|
6
|
-
FakeFS.deactivate!
|
7
|
-
end
|
8
|
-
|
9
|
-
def teardown
|
10
|
-
FakeFS.activate!
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_FakeFS_activated_is_accurate
|
14
|
-
2.times do
|
15
|
-
FakeFS.deactivate!
|
16
|
-
refute FakeFS.activated?
|
17
|
-
FakeFS.activate!
|
18
|
-
assert FakeFS.activated?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_FakeFS_method_does_not_intrude_on_global_namespace
|
23
|
-
path = 'file.txt'
|
24
|
-
|
25
|
-
FakeFS do
|
26
|
-
File.open(path, 'w') { |f| f.write 'Yatta!' }
|
27
|
-
assert File.exist?(path)
|
28
|
-
end
|
29
|
-
|
30
|
-
refute File.exist?(path)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_FakeFS_method_returns_value_of_yield
|
34
|
-
result = FakeFS do
|
35
|
-
File.open('myfile.txt', 'w') { |f| f.write 'Yatta!' }
|
36
|
-
File.read('myfile.txt')
|
37
|
-
end
|
38
|
-
|
39
|
-
assert_equal result, 'Yatta!'
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_FakeFS_method_does_not_deactivate_FakeFS_if_already_activated
|
43
|
-
FakeFS.activate!
|
44
|
-
FakeFS {}
|
45
|
-
|
46
|
-
assert FakeFS.activated?
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_FakeFS_method_can_be_nested
|
50
|
-
FakeFS do
|
51
|
-
assert FakeFS.activated?
|
52
|
-
FakeFS do
|
53
|
-
assert FakeFS.activated?
|
54
|
-
end
|
55
|
-
assert FakeFS.activated?
|
56
|
-
end
|
57
|
-
|
58
|
-
refute FakeFS.activated?
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_FakeFS_method_can_be_nested_with_FakeFS_without
|
62
|
-
FakeFS do
|
63
|
-
assert FakeFS.activated?
|
64
|
-
FakeFS.without do
|
65
|
-
refute FakeFS.activated?
|
66
|
-
end
|
67
|
-
assert FakeFS.activated?
|
68
|
-
end
|
69
|
-
|
70
|
-
refute FakeFS.activated?
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_FakeFS_method_deactivates_FakeFS_when_block_raises_exception
|
74
|
-
begin
|
75
|
-
FakeFS do
|
76
|
-
fail 'boom!'
|
77
|
-
end
|
78
|
-
rescue
|
79
|
-
'Nothing to do'
|
80
|
-
end
|
81
|
-
|
82
|
-
refute FakeFS.activated?
|
83
|
-
end
|
84
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
-
require 'fakefs/safe'
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require 'minitest/rg'
|
5
|
-
|
6
|
-
def act_on_real_fs(&block)
|
7
|
-
FakeFS.without(&block)
|
8
|
-
end
|
9
|
-
|
10
|
-
def capture_stderr
|
11
|
-
real_stderr, $stderr = $stderr, StringIO.new
|
12
|
-
|
13
|
-
# force FileUtils to use our stderr
|
14
|
-
RealFileUtils.instance_variable_set('@fileutils_output', $stderr)
|
15
|
-
|
16
|
-
yield
|
17
|
-
|
18
|
-
return $stderr.string
|
19
|
-
ensure
|
20
|
-
$stderr = real_stderr
|
21
|
-
|
22
|
-
# restore FileUtils stderr
|
23
|
-
RealFileUtils.instance_variable_set('@fileutils_output', $stderr)
|
24
|
-
end
|
25
|
-
|
26
|
-
def real_file_sandbox(path = nil)
|
27
|
-
base_path = real_file_sandbox_path
|
28
|
-
path ? File.join(base_path, path) : base_path
|
29
|
-
end
|
30
|
-
|
31
|
-
def real_file_sandbox_path
|
32
|
-
File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_sandbox'))
|
33
|
-
end
|
data/test/verify.rb
DELETED
@@ -1,34 +0,0 @@
|
|
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
|
-
# FakeFs verifier test class
|
10
|
-
class FakeFSVerifierTest < Minitest::Test
|
11
|
-
class_mapping = {
|
12
|
-
RealFile => FakeFS::File,
|
13
|
-
RealFile::Stat => FakeFS::File::Stat,
|
14
|
-
RealFileUtils => FakeFS::FileUtils,
|
15
|
-
RealDir => FakeFS::Dir,
|
16
|
-
RealFileTest => FakeFS::FileTest
|
17
|
-
}
|
18
|
-
|
19
|
-
class_mapping.each do |real_class, fake_class|
|
20
|
-
real_class.methods.each do |method|
|
21
|
-
define_method "test_#{method}_class_method" do
|
22
|
-
assert fake_class.respond_to?(method),
|
23
|
-
"#{fake_class}.#{method} not implemented"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
real_class.instance_methods.each do |method|
|
28
|
-
define_method("test_#{method}_instance_method") do
|
29
|
-
assert fake_class.instance_methods.include?(method),
|
30
|
-
"#{fake_class}##{method} not implemented"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|