fakefs 0.5.2 → 0.5.3
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.
- checksums.yaml +5 -13
- data/.gitignore +0 -1
- data/.travis.yml +1 -1
- data/fakefs.gemspec +24 -0
- data/lib/fakefs/base.rb +2 -0
- data/lib/fakefs/dir.rb +54 -0
- data/lib/fakefs/fake/symlink.rb +2 -2
- data/lib/fakefs/file.rb +34 -19
- data/lib/fakefs/file_system.rb +1 -1
- data/lib/fakefs/kernel.rb +40 -0
- data/lib/fakefs/safe.rb +1 -1
- data/lib/fakefs/spec_helpers.rb +1 -1
- data/lib/fakefs/version.rb +1 -1
- data/test/dir/tempfile_test.rb +21 -0
- data/test/fake/symlink_test.rb +15 -0
- data/test/fakefs_test.rb +107 -7
- data/test/file/stat_test.rb +20 -0
- data/test/kernel_test.rb +56 -0
- metadata +19 -27
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
Mjg3ODdmOWU0YjJkOWQwMTRiYmRkOGY0ZmQwNjBlNmRlNTBiMzM1OA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 87b3bd124e2a20133aeb85f866acb52262fc9bde
|
4
|
+
data.tar.gz: 0501ebaf21ebf9cc90464388507a5de3b9bfddc4
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YjAxMTNhOWIxYjg4ZWEzM2FhNDkyMDdhMWQ2ZDRkNjk2NDQ5YzFiMmQ2MWVh
|
11
|
-
NzkyZWE0OTA4ODFiNDAyMWFlMzY3OWU1YjYxZTgzNmE4MWNhY2E=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
OTk3M2IyMDlhODI1MWZiNTY5OWRjNWIwODRlMTkwOWNhZGZjYzljNGE5MjRh
|
14
|
-
NjJiZjM5MDU5MjkzMTYwZjQ4OTk5NmQ1NjA1Y2Q4NmI3MDFiYWVmODEzZTM4
|
15
|
-
YzYzZmEyNDQ3YmNlNGMyNDAyMGJkYzcyMDNhZjExYjJhMGM4M2I=
|
6
|
+
metadata.gz: 9c91bbfbdd6c805e7916089a10e0dad958524dc498275fc36b577196bc0cc0eedf956d1f6d1bcfd091b3ea0c0651dc345fb348b62934499a6b96316fe333d49e
|
7
|
+
data.tar.gz: ace7f7771019525affa0e05d256fdf4f4b783ca5f551464070149350ce2c6c13273453218fa481a8a36a1e26402e1c22612e238a461d05335ab7bd2cc9a1ebb4
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/fakefs.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fakefs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fakefs"
|
8
|
+
spec.version = FakeFS::Version.to_s
|
9
|
+
spec.authors = ["Chris Wanstrath", "Scott Taylor", "Jeff Hodges", "Pat Nakajima", "Brian Donovan"]
|
10
|
+
spec.email = ["chris@ozmm.org"]
|
11
|
+
spec.description = %q{A fake filesystem. Use it in your tests.}
|
12
|
+
spec.summary = %q{A fake filesystem. Use it in your tests.}
|
13
|
+
spec.homepage = "http://github.com/defunkt/fakefs"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
24
|
+
end
|
data/lib/fakefs/base.rb
CHANGED
@@ -35,6 +35,7 @@ module FakeFS
|
|
35
35
|
const_set(:FileUtils, FakeFS::FileUtils)
|
36
36
|
const_set(:FileTest, FakeFS::FileTest)
|
37
37
|
const_set(:Pathname, FakeFS::Pathname) if RUBY_VERSION >= "1.9.3"
|
38
|
+
::FakeFS::Kernel.hijack!
|
38
39
|
end
|
39
40
|
true
|
40
41
|
end
|
@@ -54,6 +55,7 @@ module FakeFS
|
|
54
55
|
const_set(:FileTest, RealFileTest)
|
55
56
|
const_set(:FileUtils, RealFileUtils)
|
56
57
|
const_set(:Pathname, RealPathname) if RUBY_VERSION >= "1.9.3"
|
58
|
+
::FakeFS::Kernel.unhijack!
|
57
59
|
end
|
58
60
|
true
|
59
61
|
end
|
data/lib/fakefs/dir.rb
CHANGED
@@ -136,6 +136,60 @@ module FakeFS
|
|
136
136
|
FileSystem.current_dir.to_s
|
137
137
|
end
|
138
138
|
|
139
|
+
if RUBY_VERSION >= '2.1'
|
140
|
+
module Tmpname # :nodoc:
|
141
|
+
module_function
|
142
|
+
|
143
|
+
def tmpdir
|
144
|
+
Dir.tmpdir
|
145
|
+
end
|
146
|
+
|
147
|
+
def make_tmpname(prefix_suffix, n)
|
148
|
+
case prefix_suffix
|
149
|
+
when String
|
150
|
+
prefix = prefix_suffix
|
151
|
+
suffix = ""
|
152
|
+
when Array
|
153
|
+
prefix = prefix_suffix[0]
|
154
|
+
suffix = prefix_suffix[1]
|
155
|
+
else
|
156
|
+
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
|
157
|
+
end
|
158
|
+
t = Time.now.strftime("%Y%m%d")
|
159
|
+
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
160
|
+
path << "-#{n}" if n
|
161
|
+
path << suffix
|
162
|
+
end
|
163
|
+
|
164
|
+
def create(basename, *rest)
|
165
|
+
if opts = Hash.try_convert(rest[-1])
|
166
|
+
opts = opts.dup if rest.pop.equal?(opts)
|
167
|
+
max_try = opts.delete(:max_try)
|
168
|
+
opts = [opts]
|
169
|
+
else
|
170
|
+
opts = []
|
171
|
+
end
|
172
|
+
tmpdir, = *rest
|
173
|
+
if $SAFE > 0 and tmpdir.tainted?
|
174
|
+
tmpdir = '/tmp'
|
175
|
+
else
|
176
|
+
tmpdir ||= tmpdir()
|
177
|
+
end
|
178
|
+
n = nil
|
179
|
+
begin
|
180
|
+
path = File.join(tmpdir, make_tmpname(basename, n))
|
181
|
+
yield(path, n, *opts)
|
182
|
+
rescue Errno::EEXIST
|
183
|
+
n ||= 0
|
184
|
+
n += 1
|
185
|
+
retry if !max_try or n < max_try
|
186
|
+
raise "cannot generate temporary name using `#{basename}' under `#{tmpdir}'"
|
187
|
+
end
|
188
|
+
path
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
139
193
|
# This code has been borrowed from Rubinius
|
140
194
|
def self.mktmpdir(prefix_suffix = nil, tmpdir = nil)
|
141
195
|
case prefix_suffix
|
data/lib/fakefs/fake/symlink.rb
CHANGED
data/lib/fakefs/file.rb
CHANGED
@@ -26,6 +26,7 @@ module FakeFS
|
|
26
26
|
|
27
27
|
FILE_CREATION_BITMASK = RealFile::CREAT
|
28
28
|
|
29
|
+
|
29
30
|
def self.extname(path)
|
30
31
|
RealFile.extname(path)
|
31
32
|
end
|
@@ -135,8 +136,7 @@ module FakeFS
|
|
135
136
|
end
|
136
137
|
|
137
138
|
def self.expand_path(file_name, dir_string=FileSystem.current_dir.to_s)
|
138
|
-
|
139
|
-
RealFile.expand_path(file_name, dir_string)
|
139
|
+
RealFile.expand_path(file_name, RealFile.expand_path(dir_string, Dir.pwd))
|
140
140
|
end
|
141
141
|
|
142
142
|
def self.basename(*args)
|
@@ -153,13 +153,17 @@ module FakeFS
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def self.read(path, *args)
|
156
|
-
|
156
|
+
options = args[-1].is_a?(Hash) ? args.pop : {}
|
157
|
+
length = args.size > 0 ? args.shift : nil
|
158
|
+
offset = args.size > 0 ? args.shift : 0
|
159
|
+
file = new(path, options)
|
157
160
|
|
158
161
|
raise Errno::ENOENT if !file.exists?
|
159
162
|
raise Errno::EISDIR, path if directory?(path)
|
160
163
|
|
161
164
|
FileSystem.find(path).atime = Time.now
|
162
|
-
file.
|
165
|
+
file.seek(offset)
|
166
|
+
file.read(length)
|
163
167
|
end
|
164
168
|
|
165
169
|
def self.readlines(path)
|
@@ -177,6 +181,8 @@ module FakeFS
|
|
177
181
|
raise Errno::ENOTDIR, "#{source} or #{dest}"
|
178
182
|
elsif file?(source) && directory?(dest)
|
179
183
|
raise Errno::EISDIR, "#{source} or #{dest}"
|
184
|
+
elsif !exist?(dirname(dest))
|
185
|
+
raise Errno::ENOENT, "#{source} or #{dest}"
|
180
186
|
end
|
181
187
|
|
182
188
|
if target = FileSystem.find(source)
|
@@ -209,18 +215,16 @@ module FakeFS
|
|
209
215
|
0
|
210
216
|
end
|
211
217
|
|
212
|
-
def self.delete(
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
FileUtils.rm(file_name)
|
218
|
+
def self.delete(*file_names)
|
219
|
+
file_names.each do |file_name|
|
220
|
+
if !exists?(file_name)
|
221
|
+
raise Errno::ENOENT, file_name
|
222
|
+
end
|
218
223
|
|
219
|
-
additional_file_names.each do |file_name|
|
220
224
|
FileUtils.rm(file_name)
|
221
225
|
end
|
222
226
|
|
223
|
-
|
227
|
+
file_names.size
|
224
228
|
end
|
225
229
|
|
226
230
|
class << self
|
@@ -272,13 +276,7 @@ module FakeFS
|
|
272
276
|
end
|
273
277
|
|
274
278
|
def self.binread(file, length = nil, offset = 0)
|
275
|
-
contents = File.read(file)
|
276
|
-
|
277
|
-
if length
|
278
|
-
contents.slice(offset, length)
|
279
|
-
else
|
280
|
-
contents
|
281
|
-
end
|
279
|
+
contents = File.read(file, length, offset, :mode => 'rb:ASCII-8BIT')
|
282
280
|
end
|
283
281
|
|
284
282
|
class Stat
|
@@ -327,6 +325,16 @@ module FakeFS
|
|
327
325
|
true
|
328
326
|
end
|
329
327
|
|
328
|
+
# World_writable and readable are platform dependent
|
329
|
+
# usually comparing with S_IROTH defined on compilation (MRI)
|
330
|
+
def world_writable?
|
331
|
+
0777
|
332
|
+
end
|
333
|
+
|
334
|
+
def world_readable?
|
335
|
+
0777
|
336
|
+
end
|
337
|
+
|
330
338
|
def nlink
|
331
339
|
@fake_file.links.size
|
332
340
|
end
|
@@ -483,6 +491,12 @@ module FakeFS
|
|
483
491
|
end
|
484
492
|
end
|
485
493
|
|
494
|
+
if RUBY_VERSION >= "1.9.1"
|
495
|
+
def self.absolute_path(file_name, dir_name = Dir.getwd)
|
496
|
+
RealFile.absolute_path(file_name, dir_name)
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
486
500
|
if RUBY_VERSION >= "1.9.2"
|
487
501
|
attr_writer :autoclose
|
488
502
|
|
@@ -533,6 +547,7 @@ module FakeFS
|
|
533
547
|
read_buf
|
534
548
|
end
|
535
549
|
|
550
|
+
|
536
551
|
private
|
537
552
|
|
538
553
|
def check_modes!
|
data/lib/fakefs/file_system.rb
CHANGED
@@ -133,7 +133,7 @@ module FakeFS
|
|
133
133
|
directories_under(dir)
|
134
134
|
end
|
135
135
|
else
|
136
|
-
dir.matches /\A#{pattern.gsub('.', '\.').gsub('?','.').gsub('*', '.*').gsub(/\{(.*?)\}/) { "(#{$1.gsub(',', '|')})" }}\Z/
|
136
|
+
dir.matches /\A#{pattern.gsub('.', '\.').gsub('?','.').gsub('*', '.*').gsub('[', '\[').gsub(']', '\]').gsub('(', '\(').gsub(')', '\)').gsub(/\{(.*?)\}/) { "(#{$1.gsub(',', '|')})" }}\Z/
|
137
137
|
end
|
138
138
|
|
139
139
|
if parts.empty? # we're done recursing
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module FakeFS
|
2
|
+
module Kernel
|
3
|
+
|
4
|
+
@captives = { :original => {}, :hijacked => {}}
|
5
|
+
class << self
|
6
|
+
attr_accessor :captives
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.hijack!
|
10
|
+
captives[:hijacked].each do |name,prc|
|
11
|
+
::Kernel.send(:define_method, name.to_sym, &prc)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.unhijack!
|
16
|
+
captives[:original].each do |name,prc|
|
17
|
+
::Kernel.send(:define_method, name.to_sym, Proc.new do |*args, &block|
|
18
|
+
::FakeFS::Kernel.captives[:original][name].call(*args, &block)
|
19
|
+
end)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def self.hijack name, &block
|
25
|
+
captives[:original][name] = ::Kernel.method(name.to_sym)
|
26
|
+
captives[:hijacked][name] = block || Proc.new { |args| }
|
27
|
+
end
|
28
|
+
|
29
|
+
hijack :open do |*args, &block|
|
30
|
+
if args.first.start_with? '|'
|
31
|
+
# This is a system command
|
32
|
+
::FakeFS::Kernel.captives[:original][:open].call(*args, &block)
|
33
|
+
else
|
34
|
+
name = args.shift
|
35
|
+
FakeFS::File.open(name, *args, &block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/fakefs/safe.rb
CHANGED
data/lib/fakefs/spec_helpers.rb
CHANGED
data/lib/fakefs/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
class TempfileTest < Test::Unit::TestCase
|
5
|
+
include FakeFS
|
6
|
+
|
7
|
+
if RUBY_VERSION >= '2.1'
|
8
|
+
def test_should_not_raise_error
|
9
|
+
FakeFS do
|
10
|
+
assert_nothing_raised do
|
11
|
+
FileUtils.mkdir_p('/tmp')
|
12
|
+
Tempfile.open('test')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
else
|
17
|
+
def test_noop
|
18
|
+
# TODO: Remove me when we add non-2.1 tests.
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/test/fake/symlink_test.rb
CHANGED
@@ -7,4 +7,19 @@ class FakeSymlinkTest < Test::Unit::TestCase
|
|
7
7
|
methods = FakeSymlink.private_instance_methods.map { |m| m.to_s }
|
8
8
|
assert methods.include?("method_missing")
|
9
9
|
end
|
10
|
+
|
11
|
+
def test_symlink_respond_to_accepts_multiple_params
|
12
|
+
fake_symlink = FakeSymlink.new('foo')
|
13
|
+
assert fake_symlink.respond_to?(:to_s, false), 'has public method \#to_s'
|
14
|
+
assert fake_symlink.respond_to?(:to_s, true), 'has public or private method \#to_s'
|
15
|
+
assert !fake_symlink.respond_to?(:initialize, false), 'has private method \#initialize'
|
16
|
+
assert fake_symlink.respond_to?(:initialize, true), 'has private method \#initialize'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_symlink_respond_to_uses_same_param_defaults
|
20
|
+
fake_symlink = FakeSymlink.new('foo')
|
21
|
+
assert_equal fake_symlink.respond_to?(:to_s), fake_symlink.entry.respond_to?(:to_s)
|
22
|
+
assert_not_equal fake_symlink.respond_to?(:to_s), fake_symlink.entry.respond_to?(:initialize)
|
23
|
+
assert_equal fake_symlink.respond_to?(:initialize), fake_symlink.entry.respond_to?(:initialize)
|
24
|
+
end
|
10
25
|
end
|
data/test/fakefs_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require "test_helper"
|
2
3
|
|
3
4
|
class FakeFSTest < Test::Unit::TestCase
|
@@ -494,6 +495,17 @@ class FakeFSTest < Test::Unit::TestCase
|
|
494
495
|
assert_nothing_raised { File.read(path, :mode => 'r:UTF-8:-') }
|
495
496
|
end
|
496
497
|
|
498
|
+
def test_file_read_respects_args
|
499
|
+
path = 'file.txt'
|
500
|
+
File.open(path, 'w') do |f|
|
501
|
+
f.write 'Yatta!'
|
502
|
+
end
|
503
|
+
|
504
|
+
assert_equal 'Ya', File.read(path, 2)
|
505
|
+
assert_equal 'at', File.read(path, 2, 1)
|
506
|
+
assert_equal 'atta!', File.read(path, nil, 1)
|
507
|
+
end
|
508
|
+
|
497
509
|
def test_can_write_to_files
|
498
510
|
path = 'file.txt'
|
499
511
|
File.open(path, 'w') do |f|
|
@@ -810,6 +822,30 @@ class FakeFSTest < Test::Unit::TestCase
|
|
810
822
|
end
|
811
823
|
end
|
812
824
|
|
825
|
+
def test_file_object_initialization_with_brackets_in_filename
|
826
|
+
filename = "bracket[1](2).txt"
|
827
|
+
expected_contents = "Yokudekimashita"
|
828
|
+
assert_nothing_raised do
|
829
|
+
File.open(filename, {:mode => "w"}){ |f| f.write "#{expected_contents}" }
|
830
|
+
end
|
831
|
+
the_file = Dir["/*"]
|
832
|
+
assert_equal the_file.length, 1
|
833
|
+
assert_equal the_file[0], "/#{filename}"
|
834
|
+
contents = File.open("/#{filename}").read()
|
835
|
+
assert_equal contents, expected_contents
|
836
|
+
end
|
837
|
+
|
838
|
+
def test_file_object_initialization_with_brackets_in_filename
|
839
|
+
# 日本語
|
840
|
+
filename = "\u65e5\u672c\u8a9e.txt"
|
841
|
+
expected_contents = "Yokudekimashita"
|
842
|
+
assert_nothing_raised do
|
843
|
+
File.open(filename, {:mode => "w"}){ |f| f.write "#{expected_contents}" }
|
844
|
+
end
|
845
|
+
contents = File.open("/#{filename}").read()
|
846
|
+
assert_equal contents, expected_contents
|
847
|
+
end
|
848
|
+
|
813
849
|
def test_file_read_errors_appropriately
|
814
850
|
assert_raise Errno::ENOENT do
|
815
851
|
File.read('anything')
|
@@ -1295,7 +1331,7 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1295
1331
|
assert_equal '/path/subdir', Dir.getwd
|
1296
1332
|
end
|
1297
1333
|
|
1298
|
-
def
|
1334
|
+
def test_current_dir_reflected_by_expand_path_with_relative_paths
|
1299
1335
|
FileUtils.mkdir_p '/path'
|
1300
1336
|
Dir.chdir '/path'
|
1301
1337
|
|
@@ -1309,6 +1345,22 @@ class FakeFSTest < Test::Unit::TestCase
|
|
1309
1345
|
assert_equal '/path/subdir/foo', File.expand_path('foo')
|
1310
1346
|
end
|
1311
1347
|
|
1348
|
+
def test_expand_path_with_parent_dir
|
1349
|
+
FakeFS.deactivate!
|
1350
|
+
real = File.expand_path('../other.file',__FILE__)
|
1351
|
+
FakeFS.activate!
|
1352
|
+
fake = File.expand_path('../other.file',__FILE__)
|
1353
|
+
assert_equal real, fake
|
1354
|
+
end
|
1355
|
+
|
1356
|
+
def test_expand_path_works_with_absolute_paths
|
1357
|
+
FakeFS.deactivate!
|
1358
|
+
home = File.expand_path('~')
|
1359
|
+
FakeFS.activate!
|
1360
|
+
assert_equal "#{home}/dir/subdir", File.expand_path('subdir', '~/dir')
|
1361
|
+
assert_equal '/somewhere/else', File.expand_path('else', '/somewhere')
|
1362
|
+
end
|
1363
|
+
|
1312
1364
|
def test_file_open_defaults_to_read
|
1313
1365
|
File.open('foo','w') { |f| f.write 'bar' }
|
1314
1366
|
assert_equal 'bar', File.open('foo') { |f| f.read }
|
@@ -2110,6 +2162,13 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2110
2162
|
end
|
2111
2163
|
end
|
2112
2164
|
|
2165
|
+
def test_rename_with_missing_dest_directory_raises_error
|
2166
|
+
FileUtils.touch("/foo")
|
2167
|
+
assert_raises(Errno::ENOENT) do
|
2168
|
+
File.rename("/foo", "/bar/foo")
|
2169
|
+
end
|
2170
|
+
end
|
2171
|
+
|
2113
2172
|
def test_hard_link_creates_file
|
2114
2173
|
FileUtils.touch("/foo")
|
2115
2174
|
|
@@ -2176,10 +2235,8 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2176
2235
|
assert !File.exists?("/bar")
|
2177
2236
|
end
|
2178
2237
|
|
2179
|
-
def
|
2180
|
-
|
2181
|
-
File.delete
|
2182
|
-
end
|
2238
|
+
def test_delete_returns_zero_when_no_filename_given
|
2239
|
+
assert_equal 0, File.delete
|
2183
2240
|
end
|
2184
2241
|
|
2185
2242
|
def test_delete_returns_number_one_when_given_one_arg
|
@@ -2458,7 +2515,6 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2458
2515
|
assert_equal File.stat('foo').gid, 1338
|
2459
2516
|
end
|
2460
2517
|
|
2461
|
-
|
2462
2518
|
def test_file_umask
|
2463
2519
|
assert_equal File.umask, RealFile.umask
|
2464
2520
|
File.umask(0740)
|
@@ -2526,6 +2582,25 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2526
2582
|
end
|
2527
2583
|
end
|
2528
2584
|
|
2585
|
+
if RUBY_VERSION >= "1.9.1"
|
2586
|
+
def test_absolute_path_with_absolute_path
|
2587
|
+
assert_equal '/foo/bar', File.absolute_path('/foo/bar')
|
2588
|
+
end
|
2589
|
+
|
2590
|
+
def test_absolute_path_with_absolute_path_with_dir_name
|
2591
|
+
assert_equal '/foo/bar', File.absolute_path('/foo/bar', '/dir')
|
2592
|
+
end
|
2593
|
+
|
2594
|
+
def test_absolute_path_with_relative_path
|
2595
|
+
assert_equal "#{Dir.getwd}foo/bar", File.absolute_path('foo/bar')
|
2596
|
+
end
|
2597
|
+
|
2598
|
+
def test_absolute_path_with_relative_path_with_dir_name
|
2599
|
+
assert_equal "/dir/foo/bar", File.absolute_path('foo/bar', '/dir')
|
2600
|
+
end
|
2601
|
+
end
|
2602
|
+
|
2603
|
+
|
2529
2604
|
if RUBY_VERSION >= "1.9.2"
|
2530
2605
|
def test_file_size
|
2531
2606
|
File.open("foo", 'w') do |f|
|
@@ -2567,6 +2642,26 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2567
2642
|
end
|
2568
2643
|
end
|
2569
2644
|
|
2645
|
+
def test_file_read_respects_hashes
|
2646
|
+
path = 'file.txt'
|
2647
|
+
File.open(path, 'w') do |f|
|
2648
|
+
f.write 'Yatta!'
|
2649
|
+
end
|
2650
|
+
|
2651
|
+
assert_equal 'ASCII-8BIT', File.read(path, :mode => 'rb').encoding.to_s
|
2652
|
+
end
|
2653
|
+
|
2654
|
+
def test_file_read_respects_args_and_hashes
|
2655
|
+
path = 'file.txt'
|
2656
|
+
File.open(path, 'w') do |f|
|
2657
|
+
f.write 'Yatta!'
|
2658
|
+
end
|
2659
|
+
|
2660
|
+
result = File.read(path, 2, 1, :mode => 'rb')
|
2661
|
+
assert_equal 'at', result
|
2662
|
+
assert_equal 'ASCII-8BIT', result.encoding.to_s
|
2663
|
+
end
|
2664
|
+
|
2570
2665
|
def test_file_write_can_write_a_file
|
2571
2666
|
File.write("testfile", "0123456789")
|
2572
2667
|
assert_equal File.read("testfile"), "0123456789"
|
@@ -2596,12 +2691,17 @@ class FakeFSTest < Test::Unit::TestCase
|
|
2596
2691
|
|
2597
2692
|
def test_can_read_binary_data_in_binary_mode
|
2598
2693
|
File.open('foo', 'wb') { |f| f << "\u0000\u0000\u0000\u0003\u0000\u0003\u0000\xA3\u0000\u0000\u0000y\u0000\u0000\u0000\u0000\u0000" }
|
2599
|
-
assert_equal "\x00\x00\x00\x03\x00\x03\x00\xA3\x00\x00\x00y\x00\x00\x00\x00\x00", File.open("foo", "rb").read
|
2694
|
+
assert_equal "\x00\x00\x00\x03\x00\x03\x00\xA3\x00\x00\x00y\x00\x00\x00\x00\x00".force_encoding('ASCII-8BIT'), File.open("foo", "rb").read
|
2600
2695
|
end
|
2601
2696
|
|
2602
2697
|
def test_can_read_binary_data_in_non_binary_mode
|
2603
2698
|
File.open('foo_non_bin', 'wb') { |f| f << "\u0000\u0000\u0000\u0003\u0000\u0003\u0000\xA3\u0000\u0000\u0000y\u0000\u0000\u0000\u0000\u0000" }
|
2604
2699
|
assert_equal "\x00\x00\x00\x03\x00\x03\x00\xA3\x00\x00\x00y\x00\x00\x00\x00\x00".force_encoding('UTF-8'), File.open("foo_non_bin", "r").read
|
2605
2700
|
end
|
2701
|
+
|
2702
|
+
def test_can_read_binary_data_using_binread
|
2703
|
+
File.open('foo', 'wb') { |f| f << "\u0000\u0000\u0000\u0003\u0000\u0003\u0000\xA3\u0000\u0000\u0000y\u0000\u0000\u0000\u0000\u0000" }
|
2704
|
+
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")
|
2705
|
+
end
|
2606
2706
|
end
|
2607
2707
|
end
|
data/test/file/stat_test.rb
CHANGED
@@ -116,6 +116,26 @@ class FileStatTest < Test::Unit::TestCase
|
|
116
116
|
assert File.mtime("/foo") > mtime
|
117
117
|
end
|
118
118
|
|
119
|
+
def test_responds_to_world_writable
|
120
|
+
FileUtils.touch("/foo")
|
121
|
+
puts File::Stat.new("/foo").world_writable?
|
122
|
+
assert File::Stat.new("/foo").world_writable? == 0777
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_responds_to_world_readable
|
126
|
+
FileUtils.touch("/foo")
|
127
|
+
puts File::Stat.new("/foo").world_readable?
|
128
|
+
assert File::Stat.new("/foo").world_readable? == 0777, "#{File::Stat.new("/foo").world_readable?}"
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_responds_to_world_readable
|
132
|
+
FakeFS do
|
133
|
+
require 'tempfile'
|
134
|
+
FileUtils.mkdir_p('/tmp')
|
135
|
+
::Tempfile.open('test', '/tmp')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
119
139
|
def test_responds_to_realpath_only_on_1_9
|
120
140
|
if RUBY_VERSION > '1.9'
|
121
141
|
assert File.respond_to?(:realpath)
|
data/test/kernel_test.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class KernelTest < Test::Unit::TestCase
|
4
|
+
include FakeFS
|
5
|
+
def setup
|
6
|
+
FakeFS.deactivate!
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
FakeFS.activate!
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_can_exec_normally
|
14
|
+
out = open("|echo 'foo'")
|
15
|
+
assert_equal "foo\n", out.gets
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_fake_kernel_can_create_subprocesses
|
19
|
+
FakeFS do
|
20
|
+
out = open("|echo 'foo'")
|
21
|
+
assert_equal "foo\n", out.gets
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_fake_kernel_can_create_new_file
|
26
|
+
FakeFS do
|
27
|
+
FileUtils.mkdir_p '/path/to/'
|
28
|
+
open('/path/to/file', "w") do |f|
|
29
|
+
f << "test"
|
30
|
+
end
|
31
|
+
assert_kind_of FakeFile, FileSystem.fs['path']['to']['file']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_fake_kernel_can_do_stuff
|
36
|
+
FakeFS do
|
37
|
+
FileUtils.mkdir_p('/tmp')
|
38
|
+
File.open('/tmp/a', 'w+') { |f| f.puts 'test' }
|
39
|
+
|
40
|
+
begin
|
41
|
+
puts open('/tmp/a').read
|
42
|
+
rescue Exception => e
|
43
|
+
puts e
|
44
|
+
puts e.backtrace
|
45
|
+
raise e
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_can_exec_normally2
|
51
|
+
out = open("|echo 'foo'")
|
52
|
+
assert_equal "foo\n", out.gets
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
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.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-
|
15
|
+
date: 2014-08-25 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|
@@ -32,44 +32,30 @@ dependencies:
|
|
32
32
|
name: rake
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
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
|
-
version: '
|
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
|
-
- -
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
version: '0'
|
52
|
-
type: :development
|
53
|
-
prerelease: false
|
54
|
-
version_requirements: !ruby/object:Gem::Requirement
|
55
|
-
requirements:
|
56
|
-
- - ! '>='
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: '0'
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: rdiscount
|
61
|
-
requirement: !ruby/object:Gem::Requirement
|
62
|
-
requirements:
|
63
|
-
- - ! '>='
|
49
|
+
- - ~>
|
64
50
|
- !ruby/object:Gem::Version
|
65
|
-
version: '
|
51
|
+
version: '2.14'
|
66
52
|
type: :development
|
67
53
|
prerelease: false
|
68
54
|
version_requirements: !ruby/object:Gem::Requirement
|
69
55
|
requirements:
|
70
|
-
- -
|
56
|
+
- - ~>
|
71
57
|
- !ruby/object:Gem::Version
|
72
|
-
version: '
|
58
|
+
version: '2.14'
|
73
59
|
description: A fake filesystem. Use it in your tests.
|
74
60
|
email:
|
75
61
|
- chris@ozmm.org
|
@@ -97,6 +83,7 @@ files:
|
|
97
83
|
- lib/fakefs/file_system.rb
|
98
84
|
- lib/fakefs/file_test.rb
|
99
85
|
- lib/fakefs/fileutils.rb
|
86
|
+
- lib/fakefs/kernel.rb
|
100
87
|
- lib/fakefs/pathname.rb
|
101
88
|
- lib/fakefs/safe.rb
|
102
89
|
- lib/fakefs/spec_helpers.rb
|
@@ -105,6 +92,7 @@ files:
|
|
105
92
|
- spec/fakefs/spec_helpers_spec.rb
|
106
93
|
- spec/spec.opts
|
107
94
|
- spec/spec_helper.rb
|
95
|
+
- test/dir/tempfile_test.rb
|
108
96
|
- test/fake/file/join_test.rb
|
109
97
|
- test/fake/file/lstat_test.rb
|
110
98
|
- test/fake/file/stat_test.rb
|
@@ -114,6 +102,7 @@ files:
|
|
114
102
|
- test/fake/symlink_test.rb
|
115
103
|
- test/fakefs_test.rb
|
116
104
|
- test/file/stat_test.rb
|
105
|
+
- test/kernel_test.rb
|
117
106
|
- test/safe_test.rb
|
118
107
|
- test/test_helper.rb
|
119
108
|
- test/verify.rb
|
@@ -127,17 +116,17 @@ require_paths:
|
|
127
116
|
- lib
|
128
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
129
118
|
requirements:
|
130
|
-
- -
|
119
|
+
- - '>='
|
131
120
|
- !ruby/object:Gem::Version
|
132
121
|
version: '0'
|
133
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
123
|
requirements:
|
135
|
-
- -
|
124
|
+
- - '>='
|
136
125
|
- !ruby/object:Gem::Version
|
137
126
|
version: '0'
|
138
127
|
requirements: []
|
139
128
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.2.
|
129
|
+
rubygems_version: 2.2.2
|
141
130
|
signing_key:
|
142
131
|
specification_version: 4
|
143
132
|
summary: A fake filesystem. Use it in your tests.
|
@@ -146,6 +135,7 @@ test_files:
|
|
146
135
|
- spec/fakefs/spec_helpers_spec.rb
|
147
136
|
- spec/spec.opts
|
148
137
|
- spec/spec_helper.rb
|
138
|
+
- test/dir/tempfile_test.rb
|
149
139
|
- test/fake/file/join_test.rb
|
150
140
|
- test/fake/file/lstat_test.rb
|
151
141
|
- test/fake/file/stat_test.rb
|
@@ -155,6 +145,8 @@ test_files:
|
|
155
145
|
- test/fake/symlink_test.rb
|
156
146
|
- test/fakefs_test.rb
|
157
147
|
- test/file/stat_test.rb
|
148
|
+
- test/kernel_test.rb
|
158
149
|
- test/safe_test.rb
|
159
150
|
- test/test_helper.rb
|
160
151
|
- test/verify.rb
|
152
|
+
has_rdoc:
|