fakefs 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CONTRIBUTORS CHANGED
@@ -4,27 +4,32 @@ Chris Wanstrath <chris@ozmm.org>
4
4
  Myles Eftos <myles@madpilot.com.au>
5
5
  Jeff Hodges <jeff@somethingsimilar.com>
6
6
  Matt Freels <matt@freels.name>
7
+ Eero Saynatkari <projects@kittensoft.org>
7
8
  Víctor Martínez <knoopx@gmail.com>
8
9
  Nick Quaranto <nick@quaran.to>
9
10
  Aaron Suggs <aaron@ktheory.com>
10
11
  Victor Costan <costan@gmail.com>
11
12
  Eric MSP Veith <eveith@wwweb-library.net>
12
13
  Jon Yurek <jyurek@thoughtbot.com>
14
+ Jared Luxenberg <jared@jaredlux.com>
15
+ Lars Gierth <lars.gierth@gmail.com>
13
16
  Greg Campbell <gtcampbell@gmail.com>
14
17
  Ben Mabey <ben@benmabey.com>
15
18
  Mark <mark@amerine.net>
16
19
  Sam Goldstein <sam@aboutus.org>
20
+ Ryan McGeary <ryan@mcgeary.org>
17
21
  Noah Paessel <knowuh@gmail.com>
18
22
  dmathieu <42@dmathieu.com>
19
23
  Mariusz Pietrzyk <wijet@wijet.pl>
20
- Lars Gierth <lars.gierth@gmail.com>
21
24
  marano <thiagomarano@gmail.com>
22
25
  jameswilding <james@jameswilding.net>
23
26
  Tymon Tobolski <i@teamon.eu>
24
27
  Scott Barron <scott@elitists.net>
28
+ Andrius Chamentauskas <andrius.chamentauskas@gmail.com>
25
29
  Keita Urashima <ursm@ursm.jp>
26
30
  David Reese <david@whatcould.com>
27
31
  msassak <msassak@gmail.com>
32
+ Andrius Chamentauskas <sinsiliux@gmail.com>
28
33
  timo3377 <tim.linquist@gmail.com>
29
34
  Mislav Marohnić <mislav.marohnic@gmail.com>
30
35
  Rob Sanheim <rsanheim@gmail.com>
data/README.markdown CHANGED
@@ -47,6 +47,13 @@ Don't Fake the FS Immediately
47
47
  # your code
48
48
  end
49
49
 
50
+ Rails
51
+ -----
52
+
53
+ If you are using fakefs in a rails project with bundler, you'll probably want to specify the following in your Gemfile:
54
+
55
+ gem "fakefs", :require => "fakefs/safe"
56
+
50
57
 
51
58
  RSpec
52
59
  -----
data/fakefs.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fakefs}
8
- s.version = "0.3.2"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Wanstrath", "Scott Taylor", "Jeff Hodges", "Pat Nakajima"]
12
- s.date = %q{2011-05-02}
12
+ s.date = %q{2011-09-05}
13
13
  s.description = %q{A fake filesystem. Use it in your tests.}
14
14
  s.email = %q{chris@ozmm.org}
15
15
  s.extra_rdoc_files = [
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
21
21
  ".rspec",
22
22
  "CONTRIBUTORS",
23
23
  "Gemfile",
24
- "Gemfile.lock",
25
24
  "LICENSE",
26
25
  "README.markdown",
27
26
  "Rakefile",
data/lib/fakefs/dir.rb CHANGED
@@ -2,8 +2,13 @@ module FakeFS
2
2
  class Dir
3
3
  include Enumerable
4
4
 
5
+ def self._check_for_valid_file(path)
6
+ raise Errno::ENOENT, "No such file or directory - #{path}" unless FileSystem.find(path)
7
+ end
8
+
5
9
  def initialize(string)
6
- raise Errno::ENOENT, string unless FileSystem.find(string)
10
+ self.class._check_for_valid_file(string)
11
+
7
12
  @path = string
8
13
  @open = true
9
14
  @pointer = 0
@@ -56,21 +61,28 @@ module FakeFS
56
61
  glob(pattern)
57
62
  end
58
63
 
64
+ def self.exists?(path)
65
+ File.exists?(path) && File.directory?(path)
66
+ end
67
+
59
68
  def self.chdir(dir, &blk)
60
69
  FileSystem.chdir(dir, &blk)
61
70
  end
62
71
 
63
72
  def self.chroot(string)
64
- # Not implemented yet
73
+ raise NotImplementedError
65
74
  end
66
75
 
67
76
  def self.delete(string)
68
- raise SystemCallError, "No such file or directory - #{string}" unless FileSystem.find(string).values.empty?
77
+ _check_for_valid_file(string)
78
+ raise Errno::ENOTEMPTY, "Directory not empty - #{string}" unless FileSystem.find(string).values.empty?
79
+
69
80
  FileSystem.delete(string)
70
81
  end
71
82
 
72
83
  def self.entries(dirname)
73
- raise SystemCallError, dirname unless FileSystem.find(dirname)
84
+ _check_for_valid_file(dirname)
85
+
74
86
  Dir.new(dirname).map { |file| File.basename(file) }
75
87
  end
76
88
 
@@ -86,8 +98,12 @@ module FakeFS
86
98
  def self.mkdir(string, integer = 0)
87
99
  parent = string.split('/')
88
100
  parent.pop
89
- raise Errno::ENOENT, "No such file or directory - #{string}" unless parent.join == "" || FileSystem.find(parent.join('/'))
101
+
102
+ joined_parent_path = parent.join
103
+
104
+ _check_for_valid_file(joined_parent_path) unless joined_parent_path == ""
90
105
  raise Errno::EEXIST, "File exists - #{string}" if File.exists?(string)
106
+
91
107
  FileUtils.mkdir_p(string)
92
108
  end
93
109
 
@@ -1,7 +1,6 @@
1
1
  module FakeFS
2
2
  class FakeSymlink
3
- attr_accessor :name, :target
4
- alias_method :to_s, :name
3
+ attr_accessor :name, :target, :parent
5
4
 
6
5
  def initialize(target)
7
6
  @target = target
@@ -19,6 +18,10 @@ module FakeFS
19
18
  parent.delete(self)
20
19
  end
21
20
 
21
+ def to_s
22
+ File.join(parent.to_s, name)
23
+ end
24
+
22
25
  def respond_to?(method)
23
26
  entry.respond_to?(method)
24
27
  end
data/lib/fakefs/file.rb CHANGED
@@ -37,7 +37,12 @@ module FakeFS
37
37
  end
38
38
 
39
39
  def self.exist?(path)
40
- !!FileSystem.find(path)
40
+ if(File.symlink?(path)) then
41
+ referent = File.expand_path(File.readlink(path), File.dirname(path))
42
+ exist?(referent)
43
+ else
44
+ !!FileSystem.find(path)
45
+ end
41
46
  end
42
47
 
43
48
  class << self
@@ -132,7 +137,7 @@ module FakeFS
132
137
 
133
138
  def self.readlink(path)
134
139
  symlink = FileSystem.find(path)
135
- FileSystem.find(symlink.target).to_s
140
+ symlink.target
136
141
  end
137
142
 
138
143
  def self.read(path)
@@ -358,7 +363,7 @@ module FakeFS
358
363
  end
359
364
 
360
365
  def to_path
361
- raise NotImplementedError
366
+ @path
362
367
  end
363
368
  end
364
369
 
@@ -398,8 +403,22 @@ module FakeFS
398
403
  (@mode & mask) != 0 if @mode.is_a?(Integer)
399
404
  end
400
405
 
406
+ # Create a missing file if the path is valid.
407
+ #
401
408
  def create_missing_file
402
- if !File.exists?(@path)
409
+ raise Errno::EISDIR, "Is a directory - #{path}" if File.directory?(@path)
410
+
411
+ if !File.exists?(@path) # Unnecessary check, probably.
412
+ dirname = RealFile.dirname @path
413
+
414
+ unless dirname == "."
415
+ dir = FileSystem.find dirname
416
+
417
+ unless dir.kind_of? FakeDir
418
+ raise Errno::ENOENT, "No such file or directory - #{path}"
419
+ end
420
+ end
421
+
403
422
  @file = FileSystem.add(path, FakeFile.new)
404
423
  end
405
424
  end
@@ -7,7 +7,7 @@ module FakeFS
7
7
  end
8
8
 
9
9
  def fs
10
- @fs ||= FakeDir.new('.')
10
+ @fs ||= FakeDir.new('/')
11
11
  end
12
12
 
13
13
  def clear
@@ -68,6 +68,7 @@ module FakeFS
68
68
  def delete(path)
69
69
  if node = FileSystem.find(path)
70
70
  node.delete
71
+ true
71
72
  end
72
73
  end
73
74
 
@@ -121,7 +122,8 @@ module FakeFS
121
122
  directories_under(dir)
122
123
  end
123
124
  else
124
- dir.reject {|k,v| /\A#{pattern.gsub('?','.').gsub('*', '.*')}\Z/ !~ k }.values
125
+ regexp_pattern = /\A#{pattern.gsub('?','.').gsub('*', '.*').gsub(/\{(.*?)\}/) { "(#{$1.gsub(',', '|')})" }}\Z/
126
+ dir.reject {|k,v| regexp_pattern !~ k }.values
125
127
  end
126
128
 
127
129
  if parts.empty? # we're done recursing
@@ -7,5 +7,9 @@ module FakeFS
7
7
  def self.directory?(file_name)
8
8
  File.directory?(file_name)
9
9
  end
10
+
11
+ def self.file?(file_name)
12
+ File.file?(file_name)
13
+ end
10
14
  end
11
15
  end
@@ -30,7 +30,7 @@ module FakeFS
30
30
 
31
31
  def rm(list, options = {})
32
32
  Array(list).each do |path|
33
- FileSystem.delete(path)
33
+ FileSystem.delete(path) or raise Errno::ENOENT.new(path)
34
34
  end
35
35
  end
36
36
 
@@ -40,9 +40,17 @@ module FakeFS
40
40
 
41
41
  def ln_s(target, path, options = {})
42
42
  options = { :force => false }.merge(options)
43
- (FileSystem.find(path) and !options[:force]) ? raise(Errno::EEXIST, path) : FileSystem.delete(path)
43
+ (FileSystem.find(path) && !options[:force]) ?
44
+ raise(Errno::EEXIST, path) :
45
+ FileSystem.delete(path)
46
+
47
+ if !options[:force] && !Dir.exists?(File.dirname(path))
48
+ raise Errno::ENOENT, path
49
+ end
50
+
44
51
  FileSystem.add(path, FakeSymlink.new(target))
45
52
  end
53
+
46
54
  def ln_sf(target, path)
47
55
  ln_s(target, path, { :force => true })
48
56
  end
@@ -1,6 +1,6 @@
1
1
  module FakeFS
2
2
  module Version
3
- VERSION = "0.3.2"
3
+ VERSION = "0.4.0"
4
4
 
5
5
  def self.to_s
6
6
  VERSION
data/test/fakefs_test.rb CHANGED
@@ -65,6 +65,12 @@ class FakeFSTest < Test::Unit::TestCase
65
65
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
66
66
  end
67
67
 
68
+ def test_unlink_errors_on_file_not_found
69
+ assert_raise Errno::ENOENT do
70
+ FileUtils.rm("/foo")
71
+ end
72
+ end
73
+
68
74
  def test_can_delete_directories
69
75
  FileUtils.mkdir_p("/path/to/dir")
70
76
  FileUtils.rmdir("/path/to/dir")
@@ -111,6 +117,11 @@ class FakeFSTest < Test::Unit::TestCase
111
117
  assert File.exists?(path)
112
118
  end
113
119
 
120
+ def test_symlink_with_missing_refferent_does_not_exist
121
+ File.symlink('/foo', '/bar')
122
+ assert !File.exists?('/bar')
123
+ end
124
+
114
125
  def test_can_create_symlinks
115
126
  FileUtils.mkdir_p(target = "/path/to/target")
116
127
  FileUtils.ln_s(target, "/path/to/link")
@@ -141,14 +152,63 @@ class FakeFSTest < Test::Unit::TestCase
141
152
  assert_equal target, File.readlink(link)
142
153
  end
143
154
 
155
+ def test_symlinks_in_different_directories
156
+ FileUtils.mkdir_p("/path/to/bar")
157
+ FileUtils.mkdir_p(target = "/path/to/foo/target")
158
+
159
+ FileUtils.ln_s(target, link = "/path/to/bar/symlink")
160
+ assert_equal target, File.readlink(link)
161
+ end
162
+
163
+ def test_symlink_with_relative_path_exists
164
+ FileUtils.touch("/file")
165
+ FileUtils.mkdir_p("/a/b")
166
+ FileUtils.ln_s("../../file", link = "/a/b/symlink")
167
+ assert File.exist?('/a/b/symlink')
168
+ end
169
+
170
+ def test_symlink_with_relative_path_and_nonexistant_file_does_not_exist
171
+ FileUtils.touch("/file")
172
+ FileUtils.mkdir_p("/a/b")
173
+ FileUtils.ln_s("../../file_foo", link = "/a/b/symlink")
174
+ assert !File.exist?('/a/b/symlink')
175
+ end
176
+
177
+ def test_symlink_with_relative_path_has_correct_target
178
+ FileUtils.touch("/file")
179
+ FileUtils.mkdir_p("/a/b")
180
+ FileUtils.ln_s("../../file", link = "/a/b/symlink")
181
+ assert_equal "../../file", File.readlink(link)
182
+ end
183
+
184
+ def test_symlinks_to_symlinks
185
+ FileUtils.mkdir_p(target = "/path/to/foo/target")
186
+ FileUtils.mkdir_p("/path/to/bar")
187
+ FileUtils.mkdir_p("/path/to/bar2")
188
+
189
+ FileUtils.ln_s(target, link1 = "/path/to/bar/symlink")
190
+ FileUtils.ln_s(link1, link2 = "/path/to/bar2/symlink")
191
+ assert_equal link1, File.readlink(link2)
192
+ end
193
+
194
+ def test_symlink_to_symlinks_should_raise_error_if_dir_doesnt_exist
195
+ FileUtils.mkdir_p(target = "/path/to/foo/target")
196
+
197
+ assert !Dir.exists?("/path/to/bar")
198
+
199
+ assert_raise Errno::ENOENT do
200
+ FileUtils.ln_s(target, "/path/to/bar/symlink")
201
+ end
202
+ end
203
+
144
204
  def test_knows_symlinks_are_symlinks
145
205
  FileUtils.mkdir_p(target = "/path/to/target")
146
206
  FileUtils.ln_s(target, link = "/path/to/symlink")
147
207
  assert File.symlink?(link)
148
208
  end
149
209
 
150
- def test_can_create_files
151
- path = '/path/to/file.txt'
210
+ def test_can_create_files_in_current_dir
211
+ path = 'file.txt'
152
212
  File.open(path, 'w') do |f|
153
213
  f.write "Yatta!"
154
214
  end
@@ -158,7 +218,74 @@ class FakeFSTest < Test::Unit::TestCase
158
218
  assert File.writable?(path)
159
219
  end
160
220
 
221
+ def test_can_create_files_in_existing_dir
222
+ FileUtils.mkdir_p "/path/to"
223
+ path = "/path/to/file.txt"
224
+
225
+ File.open(path, 'w') do |f|
226
+ f.write "Yatta!"
227
+ end
228
+
229
+ assert File.exists?(path)
230
+ assert File.readable?(path)
231
+ assert File.writable?(path)
232
+ end
233
+
234
+ def test_raises_ENOENT_trying_to_create_files_in_nonexistent_dir
235
+ path = "/path/to/file.txt"
236
+
237
+ assert_raises(Errno::ENOENT) {
238
+ File.open(path, 'w') do |f|
239
+ f.write "Yatta!"
240
+ end
241
+ }
242
+ end
243
+
244
+ def test_raises_ENOENT_trying_to_create_files_in_relative_nonexistent_dir
245
+ FileUtils.mkdir_p "/some/path"
246
+
247
+ Dir.chdir("/some/path") {
248
+ assert_raises(Errno::ENOENT) {
249
+ File.open("../foo") {|f| f.write "moo" }
250
+ }
251
+ }
252
+ end
253
+
254
+ def test_raises_ENOENT_trying_to_create_files_in_obscured_nonexistent_dir
255
+ FileUtils.mkdir_p "/some/path"
256
+
257
+ assert_raises(Errno::ENOENT) {
258
+ File.open("/some/path/../foo") {|f| f.write "moo" }
259
+ }
260
+ end
261
+
262
+ def test_raises_ENOENT_trying_to_create_tilde_referenced_nonexistent_dir
263
+ path = "~/fakefs_test_#{$$}_0000"
264
+
265
+ while File.exist? path
266
+ path = path.succ
267
+ end
268
+
269
+ assert_raises(Errno::ENOENT) {
270
+ File.open("#{path}/foo") {|f| f.write "moo" }
271
+ }
272
+ end
273
+
274
+ def test_raises_EISDIR_if_trying_to_open_existing_directory_name
275
+ path = "/path/to"
276
+
277
+ FileUtils.mkdir_p path
278
+
279
+ assert_raises(Errno::EISDIR) {
280
+ File.open(path, 'w') do |f|
281
+ f.write "Yatta!"
282
+ end
283
+ }
284
+ end
285
+
161
286
  def test_can_create_files_with_bitmasks
287
+ FileUtils.mkdir_p("/path/to")
288
+
162
289
  path = '/path/to/file.txt'
163
290
  File.open(path, File::RDWR | File::CREAT) do |f|
164
291
  f.write "Yatta!"
@@ -277,7 +404,7 @@ class FakeFSTest < Test::Unit::TestCase
277
404
  end
278
405
 
279
406
  def test_can_read_files_once_written
280
- path = '/path/to/file.txt'
407
+ path = 'file.txt'
281
408
  File.open(path, 'w') do |f|
282
409
  f.write "Yatta!"
283
410
  end
@@ -286,7 +413,7 @@ class FakeFSTest < Test::Unit::TestCase
286
413
  end
287
414
 
288
415
  def test_can_write_to_files
289
- path = '/path/to/file.txt'
416
+ path = 'file.txt'
290
417
  File.open(path, 'w') do |f|
291
418
  f << 'Yada Yada'
292
419
  end
@@ -300,11 +427,12 @@ class FakeFSTest < Test::Unit::TestCase
300
427
  end
301
428
 
302
429
  def test_can_open_file_in_binary_mode
303
- File.open("/foo", "wb") { |x| x << "a" }
304
- assert_equal "a", File.read("/foo")
430
+ File.open("foo", "wb") { |x| x << "a" }
431
+ assert_equal "a", File.read("foo")
305
432
  end
306
433
 
307
434
  def test_can_chunk_io_when_reading
435
+ FileUtils.mkdir_p "/path/to"
308
436
  path = '/path/to/file.txt'
309
437
  File.open(path, 'w') do |f|
310
438
  f << 'Yada Yada'
@@ -318,7 +446,7 @@ class FakeFSTest < Test::Unit::TestCase
318
446
  end
319
447
 
320
448
  def test_can_get_size_of_files
321
- path = '/path/to/file.txt'
449
+ path = 'file.txt'
322
450
  File.open(path, 'w') do |f|
323
451
  f << 'Yada Yada'
324
452
  end
@@ -326,20 +454,20 @@ class FakeFSTest < Test::Unit::TestCase
326
454
  end
327
455
 
328
456
  def test_can_check_if_file_has_size?
329
- path = '/path/to/file.txt'
457
+ path = 'file.txt'
330
458
  File.open(path, 'w') do |f|
331
459
  f << 'Yada Yada'
332
460
  end
333
461
  assert File.size?(path)
334
- assert_nil File.size?("/path/to/other.txt")
462
+ assert_nil File.size?("other.txt")
335
463
  end
336
464
 
337
465
  def test_can_check_size_of_empty_file
338
- path = '/path/to/file.txt'
466
+ path = 'file.txt'
339
467
  File.open(path, 'w') do |f|
340
468
  f << ''
341
469
  end
342
- assert_nil File.size?("/path/to/file.txt")
470
+ assert_nil File.size?("file.txt")
343
471
  end
344
472
 
345
473
  def test_raises_error_on_mtime_if_file_does_not_exist
@@ -349,16 +477,16 @@ class FakeFSTest < Test::Unit::TestCase
349
477
  end
350
478
 
351
479
  def test_can_return_mtime_on_existing_file
352
- path = '/path/to/file.txt'
480
+ path = 'file.txt'
353
481
  File.open(path, 'w') do |f|
354
482
  f << ''
355
483
  end
356
- assert File.mtime('/path/to/file.txt').is_a?(Time)
484
+ assert File.mtime('file.txt').is_a?(Time)
357
485
  end
358
486
 
359
487
  def test_raises_error_on_ctime_if_file_does_not_exist
360
488
  assert_raise Errno::ENOENT do
361
- File.ctime('/path/to/file.txt')
489
+ File.ctime('file.txt')
362
490
  end
363
491
  end
364
492
 
@@ -418,16 +546,16 @@ class FakeFSTest < Test::Unit::TestCase
418
546
 
419
547
  def test_can_call_utime_on_an_existing_file
420
548
  time = Time.now - 300 # Not now
421
- path = '/path/to/file.txt'
549
+ path = 'file.txt'
422
550
  File.open(path, 'w') do |f|
423
551
  f << ''
424
552
  end
425
553
  File.utime(time, time, path)
426
- assert_equal time, File.mtime('/path/to/file.txt')
554
+ assert_equal time, File.mtime('file.txt')
427
555
  end
428
556
 
429
557
  def test_utime_returns_number_of_paths
430
- path1, path2 = '/path/to/file.txt', '/path/to/another_file.txt'
558
+ path1, path2 = 'file.txt', 'another_file.txt'
431
559
  [path1, path2].each do |path|
432
560
  File.open(path, 'w') do |f|
433
561
  f << ''
@@ -437,7 +565,7 @@ class FakeFSTest < Test::Unit::TestCase
437
565
  end
438
566
 
439
567
  def test_can_read_with_File_readlines
440
- path = '/path/to/file.txt'
568
+ path = 'file.txt'
441
569
  File.open(path, 'w') do |f|
442
570
  f.puts "Yatta!", "Gatta!"
443
571
  f.puts ["woot","toot"]
@@ -447,7 +575,7 @@ class FakeFSTest < Test::Unit::TestCase
447
575
  end
448
576
 
449
577
  def test_File_close_disallows_further_access
450
- path = '/path/to/file.txt'
578
+ path = 'file.txt'
451
579
  file = File.open(path, 'w')
452
580
  file.write 'Yada'
453
581
  file.close
@@ -457,7 +585,7 @@ class FakeFSTest < Test::Unit::TestCase
457
585
  end
458
586
 
459
587
  def test_File_close_disallows_further_writes
460
- path = '/path/to/file.txt'
588
+ path = 'file.txt'
461
589
  file = File.open(path, 'w')
462
590
  file.write 'Yada'
463
591
  file.close
@@ -467,7 +595,7 @@ class FakeFSTest < Test::Unit::TestCase
467
595
  end
468
596
 
469
597
  def test_can_read_from_file_objects
470
- path = '/path/to/file.txt'
598
+ path = 'file.txt'
471
599
  File.open(path, 'w') do |f|
472
600
  f.write "Yatta!"
473
601
  end
@@ -482,7 +610,7 @@ class FakeFSTest < Test::Unit::TestCase
482
610
  end
483
611
 
484
612
  def test_knows_files_are_files
485
- path = '/path/to/file.txt'
613
+ path = 'file.txt'
486
614
  File.open(path, 'w') do |f|
487
615
  f.write "Yatta!"
488
616
  end
@@ -491,17 +619,17 @@ class FakeFSTest < Test::Unit::TestCase
491
619
  end
492
620
 
493
621
  def test_File_io_returns_self
494
- f = File.open("/foo", "w")
622
+ f = File.open("foo", "w")
495
623
  assert_equal f, f.to_io
496
624
  end
497
625
 
498
626
  def test_File_to_i_is_alias_for_filno
499
- f = File.open("/foo", "w")
627
+ f = File.open("foo", "w")
500
628
  assert_equal f.method(:to_i), f.method(:fileno)
501
629
  end
502
630
 
503
631
  def test_knows_symlink_files_are_files
504
- path = '/path/to/file.txt'
632
+ path = 'file.txt'
505
633
  File.open(path, 'w') do |f|
506
634
  f.write "Yatta!"
507
635
  end
@@ -573,16 +701,21 @@ class FakeFSTest < Test::Unit::TestCase
573
701
  FileUtils.cp_r '/path', '/otherpath'
574
702
 
575
703
  assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*']
704
+
705
+ assert_equal ['/path/bar', '/path/foo'], Dir['/path/{foo,bar}']
706
+
707
+ assert_equal ['/path/bar', '/path/bar2'], Dir['/path/bar{2,}']
576
708
  end
577
709
 
578
710
  def test_dir_glob_handles_root
579
711
  FileUtils.mkdir_p '/path'
580
712
 
581
713
  # this fails. the root dir should be named '/' but it is '.'
582
- #assert_equal ['/'], Dir['/']
714
+ assert_equal ['/'], Dir['/']
583
715
  end
584
716
 
585
717
  def test_dir_glob_handles_recursive_globs
718
+ FileUtils.mkdir_p "/one/two/three"
586
719
  File.open('/one/two/three/four.rb', 'w')
587
720
  File.open('/one/five.rb', 'w')
588
721
  assert_equal ['/one/five.rb', '/one/two/three/four.rb'], Dir['/one/**/*.rb']
@@ -591,6 +724,7 @@ class FakeFSTest < Test::Unit::TestCase
591
724
  end
592
725
 
593
726
  def test_dir_recursive_glob_ending_in_wildcards_returns_both_files_and_dirs
727
+ FileUtils.mkdir_p "/one/two/three"
594
728
  File.open('/one/two/three/four.rb', 'w')
595
729
  File.open('/one/five.rb', 'w')
596
730
  assert_equal ['/one/five.rb', '/one/two', '/one/two/three', '/one/two/three/four.rb'], Dir['/one/**/*']
@@ -608,7 +742,7 @@ class FakeFSTest < Test::Unit::TestCase
608
742
  end
609
743
 
610
744
  def test_should_report_pos_as_0_when_opening
611
- File.open("/foo", "w") do |f|
745
+ File.open("foo", "w") do |f|
612
746
  f << "foobar"
613
747
  f.rewind
614
748
 
@@ -617,7 +751,7 @@ class FakeFSTest < Test::Unit::TestCase
617
751
  end
618
752
 
619
753
  def test_should_report_pos_as_1_when_seeking_one_char
620
- File.open("/foo", "w") do |f|
754
+ File.open("foo", "w") do |f|
621
755
  f << "foobar"
622
756
 
623
757
  f.rewind
@@ -628,22 +762,22 @@ class FakeFSTest < Test::Unit::TestCase
628
762
  end
629
763
 
630
764
  def test_should_set_pos
631
- File.open("/foo", "w") do |f|
765
+ File.open("foo", "w") do |f|
632
766
  f << "foo"
633
767
  end
634
768
 
635
- fp = File.open("/foo", "r")
769
+ fp = File.open("foo", "r")
636
770
  fp.pos = 1
637
771
 
638
772
  assert_equal 1, fp.pos
639
773
  end
640
774
 
641
775
  def test_should_set_pos_with_tell_method
642
- File.open("/foo", "w") do |f|
776
+ File.open("foo", "w") do |f|
643
777
  f << "foo"
644
778
  end
645
779
 
646
- fp = File.open("/foo", "r")
780
+ fp = File.open("foo", "r")
647
781
  fp.tell = 1
648
782
 
649
783
  assert_equal 1, fp.pos
@@ -673,14 +807,14 @@ class FakeFSTest < Test::Unit::TestCase
673
807
  def test_chdir_changes_directories_like_a_boss
674
808
  # I know memes!
675
809
  FileUtils.mkdir_p '/path'
676
- assert_equal '.', FileSystem.fs.name
810
+ assert_equal '/', FileSystem.fs.name
677
811
  assert_equal({}, FileSystem.fs['path'])
678
812
  Dir.chdir '/path' do
679
813
  File.open('foo', 'w') { |f| f.write 'foo'}
680
814
  File.open('foobar', 'w') { |f| f.write 'foo'}
681
815
  end
682
816
 
683
- assert_equal '.', FileSystem.fs.name
817
+ assert_equal '/', FileSystem.fs.name
684
818
  assert_equal(['foo', 'foobar'], FileSystem.fs['path'].keys.sort)
685
819
 
686
820
  c = nil
@@ -1211,11 +1345,17 @@ class FakeFSTest < Test::Unit::TestCase
1211
1345
  FileUtils.touch("/this/path/should/be/here/#{f}")
1212
1346
  end
1213
1347
 
1214
- assert_raises(SystemCallError) do
1348
+ assert_raises(Errno::ENOTEMPTY) do
1215
1349
  Dir.delete('/this/path/should/be/here')
1216
1350
  end
1217
1351
  end
1218
1352
 
1353
+ def test_directory_class_delete_does_not_work_if_dir_path_cannot_be_found
1354
+ assert_raises(Errno::ENOENT) do
1355
+ Dir.delete('/this/path/should/not/be/here')
1356
+ end
1357
+ end
1358
+
1219
1359
  def test_directory_entries
1220
1360
  test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1221
1361
 
@@ -1244,6 +1384,12 @@ class FakeFSTest < Test::Unit::TestCase
1244
1384
  test.each { |t| assert yielded.include?(t) }
1245
1385
  end
1246
1386
 
1387
+ def test_directory_entries_does_not_work_if_dir_path_cannot_be_found
1388
+ assert_raises(Errno::ENOENT) do
1389
+ Dir.delete('/this/path/should/not/be/here')
1390
+ end
1391
+ end
1392
+
1247
1393
  def test_directory_foreach
1248
1394
  test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1249
1395
 
@@ -1468,14 +1614,6 @@ class FakeFSTest < Test::Unit::TestCase
1468
1614
  end
1469
1615
  end
1470
1616
 
1471
- def test_delete_does_not_raise_error_when_second_file_does_not_exist
1472
- FileUtils.touch("/foo")
1473
-
1474
- assert_nothing_raised do
1475
- File.delete("/foo", "/bar")
1476
- end
1477
- end
1478
-
1479
1617
  def test_unlink_is_alias_for_delete
1480
1618
  assert_equal File.method(:unlink), File.method(:delete)
1481
1619
  end
@@ -1584,6 +1722,20 @@ class FakeFSTest < Test::Unit::TestCase
1584
1722
  assert !FileTest.directory?('/path/to/somedir')
1585
1723
  end
1586
1724
 
1725
+ def test_filetest_file_returns_correct_values
1726
+ FileUtils.mkdir_p("/path/to")
1727
+
1728
+ path = '/path/to/file.txt'
1729
+ File.open(path, 'w') { |f| f.write "Yatta!" }
1730
+ assert FileTest.file?(path)
1731
+
1732
+ FileUtils.rm path
1733
+ assert !FileTest.file?(path)
1734
+
1735
+ FileUtils.mkdir_p '/path/to/somedir'
1736
+ assert !FileTest.file?('/path/to/somedir')
1737
+ end
1738
+
1587
1739
  def test_pathname_exists_returns_correct_value
1588
1740
  FileUtils.touch "foo"
1589
1741
  assert Pathname.new("foo").exist?
@@ -1651,5 +1803,11 @@ class FakeFSTest < Test::Unit::TestCase
1651
1803
  assert_equal false, f.autoclose?
1652
1804
  end
1653
1805
  end
1806
+
1807
+ def test_to_path
1808
+ File.new("foo", 'w') do |f|
1809
+ assert_equal "foo", f.to_path
1810
+ end
1811
+ end
1654
1812
  end
1655
1813
  end
data/test/safe_test.rb CHANGED
@@ -10,7 +10,7 @@ class FakeFSSafeTest < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  def test_FakeFS_method_does_not_intrude_on_global_namespace
13
- path = '/path/to/file.txt'
13
+ path = 'file.txt'
14
14
 
15
15
  FakeFS do
16
16
  File.open(path, 'w') { |f| f.write "Yatta!" }
data/test/verify.rb CHANGED
@@ -24,7 +24,7 @@ class FakeFSVerifierTest < Test::Unit::TestCase
24
24
 
25
25
  real_class.instance_methods.each do |method|
26
26
  define_method("test #{method} instance method") do
27
- assert fake_class.instance_methods.include?(method), "#{fake_class}##{name} not implemented"
27
+ assert fake_class.instance_methods.include?(method), "#{fake_class}##{method} not implemented"
28
28
  end
29
29
  end
30
30
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fakefs
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.2
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris Wanstrath
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2011-05-02 00:00:00 -04:00
16
+ date: 2011-09-05 00:00:00 -04:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -74,7 +74,6 @@ files:
74
74
  - .rspec
75
75
  - CONTRIBUTORS
76
76
  - Gemfile
77
- - Gemfile.lock
78
77
  - LICENSE
79
78
  - README.markdown
80
79
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,35 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.1.2)
5
- git (1.2.5)
6
- jeweler (1.6.0)
7
- bundler (~> 1.0.0)
8
- git (>= 1.2.5)
9
- rake
10
- json (1.5.1)
11
- rake (0.8.7)
12
- rdiscount (1.6.8)
13
- rdoc (2.4.3)
14
- rspec (2.5.0)
15
- rspec-core (~> 2.5.0)
16
- rspec-expectations (~> 2.5.0)
17
- rspec-mocks (~> 2.5.0)
18
- rspec-core (2.5.1)
19
- rspec-expectations (2.5.0)
20
- diff-lcs (~> 1.1.2)
21
- rspec-mocks (2.5.0)
22
- sdoc (0.2.20)
23
- json (>= 1.1.3)
24
- rdoc (= 2.4.3)
25
- sdoc-helpers (0.1.4)
26
- sdoc (~> 0.2)
27
-
28
- PLATFORMS
29
- ruby
30
-
31
- DEPENDENCIES
32
- jeweler
33
- rdiscount
34
- rspec
35
- sdoc-helpers