virtfs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +8 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +154 -0
  8. data/Rakefile +5 -0
  9. data/lib/virtfs-nativefs-thick.rb +1 -0
  10. data/lib/virtfs-nativefs-thin.rb +1 -0
  11. data/lib/virtfs.rb +38 -0
  12. data/lib/virtfs/activation.rb +97 -0
  13. data/lib/virtfs/block_io.rb +140 -0
  14. data/lib/virtfs/byte_range.rb +71 -0
  15. data/lib/virtfs/context.rb +300 -0
  16. data/lib/virtfs/context_manager.rb +175 -0
  17. data/lib/virtfs/context_switch_class_methods.rb +96 -0
  18. data/lib/virtfs/delegate_module.rb +40 -0
  19. data/lib/virtfs/dir_instance_delegate.rb +3 -0
  20. data/lib/virtfs/exception.rb +13 -0
  21. data/lib/virtfs/file_instance_delegate.rb +3 -0
  22. data/lib/virtfs/file_modes_and_options.rb +293 -0
  23. data/lib/virtfs/find_class_methods.rb +106 -0
  24. data/lib/virtfs/io_buffer.rb +133 -0
  25. data/lib/virtfs/io_instance_delegate.rb +3 -0
  26. data/lib/virtfs/kernel.rb +146 -0
  27. data/lib/virtfs/nativefs/thick.rb +30 -0
  28. data/lib/virtfs/nativefs/thick/dir_class_methods.rb +38 -0
  29. data/lib/virtfs/nativefs/thick/file_class_methods.rb +178 -0
  30. data/lib/virtfs/nativefs/thin.rb +32 -0
  31. data/lib/virtfs/nativefs/thin/dir.rb +30 -0
  32. data/lib/virtfs/nativefs/thin/dir_class_methods.rb +41 -0
  33. data/lib/virtfs/nativefs/thin/file.rb +112 -0
  34. data/lib/virtfs/nativefs/thin/file_class_methods.rb +181 -0
  35. data/lib/virtfs/protofs/protofs.rb +7 -0
  36. data/lib/virtfs/protofs/protofs_base.rb +12 -0
  37. data/lib/virtfs/protofs/protofs_dir.rb +13 -0
  38. data/lib/virtfs/protofs/protofs_dir_class.rb +31 -0
  39. data/lib/virtfs/protofs/protofs_file.rb +27 -0
  40. data/lib/virtfs/protofs/protofs_file_class.rb +136 -0
  41. data/lib/virtfs/stat.rb +100 -0
  42. data/lib/virtfs/thin_dir_delegator.rb +79 -0
  43. data/lib/virtfs/thin_file_delegator.rb +77 -0
  44. data/lib/virtfs/thin_io_delegator_methods.rb +301 -0
  45. data/lib/virtfs/thin_io_delegator_methods_bufferio.rb +337 -0
  46. data/lib/virtfs/v_dir.rb +238 -0
  47. data/lib/virtfs/v_file.rb +480 -0
  48. data/lib/virtfs/v_io.rb +243 -0
  49. data/lib/virtfs/v_pathname.rb +128 -0
  50. data/lib/virtfs/version.rb +3 -0
  51. data/spec/activate_spec.rb +202 -0
  52. data/spec/chroot_spec.rb +120 -0
  53. data/spec/context_manager_class_spec.rb +246 -0
  54. data/spec/context_manager_instance_spec.rb +255 -0
  55. data/spec/context_spec.rb +335 -0
  56. data/spec/data/UTF-16LE-data.txt +0 -0
  57. data/spec/data/UTF-8-data.txt +212 -0
  58. data/spec/dir_class_spec.rb +506 -0
  59. data/spec/dir_instance_spec.rb +208 -0
  60. data/spec/file_class_spec.rb +2106 -0
  61. data/spec/file_instance_spec.rb +154 -0
  62. data/spec/file_modes_and_options_spec.rb +1556 -0
  63. data/spec/find_spec.rb +142 -0
  64. data/spec/io_bufferio_size_shared_examples.rb +371 -0
  65. data/spec/io_bufferio_size_spec.rb +861 -0
  66. data/spec/io_bufferio_spec.rb +801 -0
  67. data/spec/io_class_spec.rb +145 -0
  68. data/spec/io_instance_spec.rb +516 -0
  69. data/spec/kernel_spec.rb +285 -0
  70. data/spec/mount_spec.rb +186 -0
  71. data/spec/nativefs_local_root_spec.rb +132 -0
  72. data/spec/path_spec.rb +39 -0
  73. data/spec/spec_helper.rb +126 -0
  74. data/tasks/rspec.rake +3 -0
  75. data/tasks/yard.rake +7 -0
  76. data/test/UTF-8-demo.txt +212 -0
  77. data/test/bench.rb +18 -0
  78. data/test/bio_internal_test.rb +45 -0
  79. data/test/delegate_io.rb +31 -0
  80. data/test/delegate_module.rb +62 -0
  81. data/test/encode_test.rb +42 -0
  82. data/test/enoent_test.rb +30 -0
  83. data/test/namespace_test.rb +42 -0
  84. data/test/read_block_valid_encoding.rb +44 -0
  85. data/test/read_test.rb +78 -0
  86. data/test/stream_readers.rb +46 -0
  87. data/test/utf-16-demo.txt +0 -0
  88. data/test/utf8_to_utf16.rb +77 -0
  89. data/test/wrapper_test.rb +34 -0
  90. data/virtfs.gemspec +29 -0
  91. metadata +230 -0
@@ -0,0 +1,506 @@
1
+ require 'spec_helper'
2
+ require 'tmpdir'
3
+
4
+ describe VirtFS::VDir, "(#{$fs_interface} interface)" do
5
+ before(:all) do
6
+ @full_path = File.expand_path(__FILE__)
7
+ @rel_path = File.basename(@full_path)
8
+ @spec_dir = File.dirname(@full_path)
9
+ @this_dir = VfsRealDir.getwd
10
+ @root = File::SEPARATOR
11
+ end
12
+
13
+ before(:each) do
14
+ reset_context
15
+ end
16
+
17
+ describe ".[]" do
18
+ context "with no filesystems mounted" do
19
+ it "should return empty array when in a nonexistent directory" do
20
+ VirtFS.cwd = "/not_a_dir" # bypass existence checks.
21
+ expect(VirtFS::VDir["*"]).to match_array([])
22
+ end
23
+
24
+ it "should return empty array when in a directory that exists in the native FS" do
25
+ VirtFS.cwd = @this_dir # bypass existence checks.
26
+ expect(VirtFS::VDir["*"]).to match_array([])
27
+ end
28
+ end
29
+
30
+ context "with FS mounted on '/'" do
31
+ before(:each) do
32
+ @native_fs = nativefs_class.new
33
+ VirtFS.mount(@native_fs, @root)
34
+ end
35
+
36
+ it "should return empty array when in a nonexistent directory" do
37
+ VirtFS.cwd = "/not_a_dir" # bypass existence checks.
38
+ expect(VirtFS::VDir["*"]).to match_array([])
39
+ end
40
+
41
+ it "should enumerate the same file names as the standard Dir.glob - simple glob" do
42
+ VfsRealDir.chdir(@this_dir) do # for VfsRealDir.glob
43
+ VirtFS.dir_chdir(@this_dir)
44
+ expect(VirtFS::VDir["*"]).to match_array(VfsRealDir["*"])
45
+ expect(VirtFS::VDir["*/*.rb"]).to match_array(VfsRealDir["*/*.rb"])
46
+ end
47
+ end
48
+
49
+ it "should enumerate the same file names as the standard Dir.glob - relative glob" do
50
+ VfsRealDir.chdir(@spec_dir) do # for VfsRealDir.glob
51
+ VirtFS.dir_chdir(@spec_dir)
52
+ expect(VirtFS::VDir["../**/*.rb"] - VfsRealDir["../**/*.rb"]).to match_array([])
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ describe ".chdir" do
59
+ context "with no filesystems mounted" do
60
+ it "should raise Errno::ENOENT when given a nonexistent directory" do
61
+ expect do
62
+ VirtFS::VDir.chdir("nonexistent_directory")
63
+ end.to raise_error(
64
+ Errno::ENOENT, "No such file or directory - nonexistent_directory"
65
+ )
66
+ end
67
+
68
+ it "should raise Errno::ENOENT when given a directory that exists in the native FS" do
69
+ expect do
70
+ VirtFS::VDir.chdir(@this_dir)
71
+ end.to raise_error(
72
+ Errno::ENOENT, "No such file or directory - #{@this_dir}"
73
+ )
74
+ end
75
+ end
76
+
77
+ context "with FS mounted on '/'" do
78
+ before(:each) do
79
+ @native_fs = nativefs_class.new
80
+ VirtFS.mount(@native_fs, @root)
81
+ end
82
+
83
+ it "should raise Errno::ENOENT when directory doesn't exist" do
84
+ expect do
85
+ VirtFS::VDir.chdir("nonexistent_directory")
86
+ end.to raise_error(
87
+ Errno::ENOENT, "No such file or directory - nonexistent_directory"
88
+ )
89
+ end
90
+
91
+ it "should return 0 when no block given" do
92
+ expect(VirtFS::VDir.chdir(@this_dir)).to eq(0)
93
+ end
94
+
95
+ it "should return last object of block, when block given" do
96
+ expect(VirtFS::VDir.chdir(@this_dir) { true }).to be true
97
+ end
98
+
99
+ it "should yield the new current directory to the block" do
100
+ expect(VirtFS::VDir.chdir(@this_dir) { |path| path == @this_dir }).to be true
101
+ end
102
+
103
+ it "should change to the home directory when called without an argument" do
104
+ VirtFS::VDir.chdir
105
+ expect(VirtFS::VDir.getwd).to eq(VfsRealDir.home)
106
+ end
107
+ end
108
+ end
109
+
110
+ describe ".delete .rmdir .unlink" do
111
+ context "with no filesystems mounted" do
112
+ it "should raise Errno::ENOENT when parent doesn't exist" do
113
+ expect do
114
+ VirtFS.cwd = "/not_a_dir" # bypass existence checks.
115
+ VirtFS::VDir.delete("foo.d")
116
+ end.to raise_error(
117
+ Errno::ENOENT, "No such file or directory - /not_a_dir"
118
+ )
119
+ end
120
+
121
+ it "should raise Errno::ENOENT parent does exist in the native FS" do
122
+ expect do
123
+ VirtFS.cwd = @this_dir # bypass existence checks.
124
+ VirtFS::VDir.delete("foo.d")
125
+ end.to raise_error(
126
+ Errno::ENOENT, /No such file or directory -/
127
+ )
128
+ end
129
+ end
130
+
131
+ context "with FS mounted on '/'" do
132
+ before(:each) do
133
+ @native_fs = nativefs_class.new
134
+ VirtFS.mount(@native_fs, @root)
135
+ end
136
+
137
+ it "should raise Errno::ENOENT when directory does exist in the native FS" do
138
+ expect do
139
+ VirtFS::VDir.delete("/not_a_dir/foo.d")
140
+ end.to raise_error(
141
+ Errno::ENOENT, /No such file or directory/
142
+ )
143
+ end
144
+
145
+ it "should delete the directory - given full path" do
146
+ VfsRealDir.mktmpdir("vfs_spec_tmp-") do |parent_dir|
147
+ dir_path = VfsRealFile.join(parent_dir, "foo.d")
148
+ expect(VirtFS::VDir.mkdir(dir_path)).to eq(0)
149
+ expect(VfsRealDir.exist?(dir_path)).to be true
150
+ expect(VirtFS::VDir.delete(dir_path)).to eq(0)
151
+ expect(VfsRealDir.exist?(dir_path)).to be false
152
+ end
153
+ end
154
+
155
+ it "should delete the directory - given relative path" do
156
+ VfsRealDir.mktmpdir("vfs_spec_tmp-") do |parent_dir|
157
+ dir_path = VfsRealFile.join(parent_dir, "foo.d")
158
+ VirtFS::VDir.chdir(parent_dir)
159
+ expect(VirtFS::VDir.mkdir("foo.d")).to eq(0)
160
+ expect(VfsRealDir.exist?(dir_path)).to be true
161
+ expect(VirtFS::VDir.delete("foo.d")).to eq(0)
162
+ expect(VfsRealDir.exist?(dir_path)).to be false
163
+ end
164
+ end
165
+ end
166
+ end
167
+
168
+ describe ".entries" do
169
+ context "with no filesystems mounted" do
170
+ it "should raise Errno::ENOENT when given a nonexistent directory" do
171
+ expect do
172
+ VirtFS::VDir.entries("nonexistent_directory")
173
+ end.to raise_error(
174
+ Errno::ENOENT, "No such file or directory - nonexistent_directory"
175
+ )
176
+ end
177
+
178
+ it "should raise Errno::ENOENT when given a directory that exists in the native FS" do
179
+ expect do
180
+ VirtFS::VDir.entries(@this_dir)
181
+ end.to raise_error(
182
+ Errno::ENOENT, "No such file or directory - #{@this_dir}"
183
+ )
184
+ end
185
+ end
186
+
187
+ context "with FS mounted on #{@root}" do
188
+ before(:each) do
189
+ @native_fs = nativefs_class.new
190
+ VirtFS.mount(@native_fs, @root)
191
+ VirtFS.dir_chdir(@this_dir)
192
+ end
193
+
194
+ it "should raise Errno::ENOENT when given a nonexistent directory" do
195
+ expect do
196
+ VirtFS::VDir.entries("nonexistent_directory")
197
+ end.to raise_error(
198
+ Errno::ENOENT, /No such file or directory/
199
+ )
200
+ end
201
+
202
+ it "should, given full path, return the same file names as the real Dir.entries" do
203
+ expect(VirtFS::VDir.entries(@this_dir)).to eq(VfsRealDir.entries(@this_dir))
204
+ end
205
+
206
+ it "should, given relative path, return the same file names as the real Dir.entries" do
207
+ expect(VirtFS::VDir.entries(".")).to eq(VfsRealDir.entries("."))
208
+ end
209
+ end
210
+ end
211
+
212
+ describe ".exist? .exists?" do
213
+ context "with no filesystems mounted" do
214
+ it "should return false when given a nonexistent directory" do
215
+ expect(VirtFS::VDir.exist?("nonexistent_directory")).to be false
216
+ end
217
+
218
+ it "should return false when given a directory that exists in the native FS" do
219
+ expect(VirtFS::VDir.exist?(@this_dir)).to be false
220
+ end
221
+ end
222
+
223
+ context "with FS mounted on #{@root}" do
224
+ before(:each) do
225
+ @native_fs = nativefs_class.new
226
+ VirtFS.mount(@native_fs, @root)
227
+ VirtFS.dir_chdir(@this_dir)
228
+ end
229
+
230
+ it "should, given full path, return true for this directory" do
231
+ expect(VirtFS::VDir.exist?(@this_dir)).to be true
232
+ end
233
+
234
+ it "should, given relative path, return true for this directory" do
235
+ expect(VirtFS::VDir.exist?(".")).to be true
236
+ end
237
+ end
238
+ end
239
+
240
+ describe ".foreach" do
241
+ context "with no filesystems mounted" do
242
+ it "should raise Errno::ENOENT when given a nonexistent directory" do
243
+ expect do
244
+ VirtFS::VDir.foreach("nonexistent_directory")
245
+ end.to raise_error(
246
+ Errno::ENOENT, "No such file or directory - nonexistent_directory"
247
+ )
248
+ end
249
+
250
+ it "should raise Errno::ENOENT when given a directory that exists in the native FS" do
251
+ expect do
252
+ VirtFS::VDir.foreach(@this_dir)
253
+ end.to raise_error(
254
+ Errno::ENOENT, "No such file or directory - #{@this_dir}"
255
+ )
256
+ end
257
+ end
258
+
259
+ context "with FS mounted on #{@root}" do
260
+ before(:each) do
261
+ @native_fs = nativefs_class.new
262
+ VirtFS.mount(@native_fs, @root)
263
+ VirtFS.dir_chdir(@this_dir)
264
+ end
265
+
266
+ it "should raise Errno::ENOENT when given a nonexistent directory" do
267
+ expect do
268
+ VirtFS::VDir.foreach("nonexistent_directory").to_a
269
+ end.to raise_error(
270
+ Errno::ENOENT, /No such file or directory/
271
+ )
272
+ end
273
+
274
+ it "should return an enum when no block is given" do
275
+ expect(VirtFS::VDir.foreach(@this_dir)).to be_kind_of(Enumerator)
276
+ end
277
+
278
+ it "should return nil when block is given" do
279
+ expect(VirtFS::VDir.foreach(@this_dir) { |f| f }).to be_nil
280
+ end
281
+
282
+ it "should, given full path, return the same file names as the real Dir.foreach" do
283
+ expect(VirtFS::VDir.foreach(@this_dir).to_a).to eq(VfsRealDir.foreach(@this_dir).to_a)
284
+ end
285
+
286
+ it "should, given relative path, return the same file names as the real Dir.foreach" do
287
+ expect(VirtFS::VDir.foreach(".").to_a).to eq(VfsRealDir.foreach(".").to_a)
288
+ end
289
+ end
290
+ end
291
+
292
+ describe ".getwd .pwd" do
293
+ it "should default to '#{@root}'" do
294
+ expect(VirtFS::VDir.getwd).to eq(@root)
295
+ end
296
+
297
+ it "return the value set by VirtFS.dir_chdir" do
298
+ VirtFS.cwd = @this_dir
299
+ expect(VirtFS::VDir.getwd).to eq(@this_dir)
300
+ end
301
+ end
302
+
303
+ describe ".glob" do
304
+ context "with no filesystems mounted" do
305
+ it "should return empty array when in a nonexistent directory" do
306
+ VirtFS.cwd = "/not_a_dir" # bypass existence checks.
307
+ expect(VirtFS::VDir.glob("*")).to match_array([])
308
+ end
309
+
310
+ it "should return empty array when in a directory that exists in the native FS" do
311
+ VirtFS.cwd = @this_dir # bypass existence checks.
312
+ expect(VirtFS::VDir.glob("*")).to match_array([])
313
+ end
314
+ end
315
+
316
+ context "with FS mounted on '/'" do
317
+ before(:each) do
318
+ @native_fs = nativefs_class.new
319
+ VirtFS.mount(@native_fs, @root)
320
+ end
321
+
322
+ it "should return empty array when in a nonexistent directory" do
323
+ VirtFS.cwd = "/not_a_dir" # bypass existence checks.
324
+ expect(VirtFS::VDir.glob("*")).to match_array([])
325
+ end
326
+
327
+ it "should enumerate the same file names as the standard Dir.glob - simple glob" do
328
+ VfsRealDir.chdir(@this_dir) do # for VfsRealDir.glob
329
+ VirtFS.dir_chdir(@this_dir)
330
+ expect(VirtFS::VDir.glob("*")).to match_array(VfsRealDir.glob("*"))
331
+ expect(VirtFS::VDir.glob("*/*.rb")).to match_array(VfsRealDir.glob("*/*.rb"))
332
+ end
333
+ end
334
+
335
+ it "should enumerate the same file names as the standard Dir.glob - relative glob" do
336
+ VfsRealDir.chdir(@spec_dir) do # for VfsRealDir.glob
337
+ VirtFS.dir_chdir(@spec_dir)
338
+ expect(VirtFS::VDir.glob("../**/*.rb") - VfsRealDir.glob("../**/*.rb")).to match_array([])
339
+ end
340
+ end
341
+ end
342
+ end
343
+
344
+ describe ".home" do
345
+ before(:each) do
346
+ @native_fs = nativefs_class.new
347
+ VirtFS.mount(@native_fs, @root)
348
+ end
349
+
350
+ it "should return the home directory of the current user, when called without an argument" do
351
+ expect(VirtFS::VDir.home).to eq(VfsRealDir.home)
352
+ end
353
+
354
+ it "should return the home directory of the given user" do
355
+ expect(VirtFS::VDir.home("root")).to eq(VfsRealDir.home("root"))
356
+ end
357
+ end
358
+
359
+ describe ".mkdir" do
360
+ context "with no filesystems mounted" do
361
+ it "should raise Errno::ENOENT when parent doesn't exist" do
362
+ expect do
363
+ VirtFS.cwd = "/not_a_dir" # bypass existence checks.
364
+ VirtFS::VDir.mkdir("foo.d")
365
+ end.to raise_error(
366
+ Errno::ENOENT, "No such file or directory - /not_a_dir"
367
+ )
368
+ end
369
+
370
+ it "should raise Errno::ENOENT parent does exist in the native FS" do
371
+ expect do
372
+ VirtFS.cwd = @this_dir # bypass existence checks.
373
+ VirtFS::VDir.mkdir("foo.d")
374
+ end.to raise_error(
375
+ Errno::ENOENT, /No such file or directory -/
376
+ )
377
+ end
378
+ end
379
+
380
+ context "with FS mounted on '/'" do
381
+ before(:each) do
382
+ @native_fs = nativefs_class.new
383
+ VirtFS.mount(@native_fs, @root)
384
+ end
385
+
386
+ it "should raise Errno::ENOENT when parent does exist in the native FS" do
387
+ expect do
388
+ VirtFS::VDir.mkdir("/not_a_dir/foo.d")
389
+ end.to raise_error(
390
+ Errno::ENOENT, /No such file or directory/
391
+ )
392
+ end
393
+
394
+ it "should create the directory in the parent directory - given full path" do
395
+ VfsRealDir.mktmpdir("vfs_spec_tmp-") do |parent_dir|
396
+ dir_path = VfsRealFile.join(parent_dir, "foo.d")
397
+ expect(VirtFS::VDir.mkdir(dir_path)).to eq(0)
398
+ expect(VfsRealDir.exist?(dir_path)).to be true
399
+ end
400
+ end
401
+
402
+ it "should create the directory in the parent directory - given relative path" do
403
+ VfsRealDir.mktmpdir("vfs_spec_tmp-") do |parent_dir|
404
+ dir_path = VfsRealFile.join(parent_dir, "foo.d")
405
+ VirtFS::VDir.chdir(parent_dir)
406
+ expect(VirtFS::VDir.mkdir("foo.d")).to eq(0)
407
+ expect(VfsRealDir.exist?(dir_path)).to be true
408
+ end
409
+ end
410
+ end
411
+ end
412
+
413
+ describe ".new" do
414
+ context "with no filesystems mounted" do
415
+ it "should raise Errno::ENOENT when directory doesn't exist" do
416
+ expect do
417
+ VirtFS::VDir.new("/not_a_dir")
418
+ end.to raise_error(
419
+ Errno::ENOENT, "No such file or directory - /not_a_dir"
420
+ )
421
+ end
422
+
423
+ it "should raise Errno::ENOENT directory does exist in the native FS" do
424
+ expect do
425
+ VirtFS::VDir.new(@this_dir)
426
+ end.to raise_error(
427
+ Errno::ENOENT, /No such file or directory -/
428
+ )
429
+ end
430
+ end
431
+
432
+ context "with FS mounted on '/'" do
433
+ before(:each) do
434
+ @native_fs = nativefs_class.new
435
+ VirtFS.mount(@native_fs, @root)
436
+ end
437
+
438
+ it "should raise Errno::ENOENT when directory doesn't exist" do
439
+ expect do
440
+ VirtFS::VDir.new("/not_a_dir")
441
+ end.to raise_error(
442
+ Errno::ENOENT, /No such file or directory/
443
+ )
444
+ end
445
+
446
+ it "should return a directory object - given full path" do
447
+ expect(VirtFS::VDir.new(@this_dir)).to be_kind_of(VirtFS::VDir)
448
+ end
449
+
450
+ it "should return a directory object - given relative path" do
451
+ VfsRealDir.mktmpdir("vfs_spec_tmp-") do |parent_dir|
452
+ VirtFS::VDir.chdir(parent_dir)
453
+ expect(VirtFS::VDir.mkdir("foo.d")).to eq(0)
454
+ expect(VirtFS::VDir.new("foo.d")).to be_kind_of(VirtFS::VDir)
455
+ end
456
+ end
457
+ end
458
+ end
459
+
460
+ describe ".open" do
461
+ context "with no filesystems mounted" do
462
+ it "should raise Errno::ENOENT when directory doesn't exist" do
463
+ expect do
464
+ VirtFS::VDir.open("/not_a_dir")
465
+ end.to raise_error(
466
+ Errno::ENOENT, "No such file or directory - /not_a_dir"
467
+ )
468
+ end
469
+
470
+ it "should raise Errno::ENOENT directory does exist in the native FS" do
471
+ expect do
472
+ VirtFS::VDir.open(@this_dir)
473
+ end.to raise_error(
474
+ Errno::ENOENT, /No such file or directory -/
475
+ )
476
+ end
477
+ end
478
+
479
+ context "with FS mounted on '/'" do
480
+ before(:each) do
481
+ @native_fs = nativefs_class.new
482
+ VirtFS.mount(@native_fs, @root)
483
+ end
484
+
485
+ it "should raise Errno::ENOENT when directory doesn't exist" do
486
+ expect do
487
+ VirtFS::VDir.new("/not_a_dir")
488
+ end.to raise_error(
489
+ Errno::ENOENT, /No such file or directory/
490
+ )
491
+ end
492
+
493
+ it "should return a directory object - when no block given" do
494
+ expect(VirtFS::VDir.open(@this_dir)).to be_kind_of(VirtFS::VDir)
495
+ end
496
+
497
+ it "should yield a directory object to the block - when block given" do
498
+ VirtFS::VDir.open(@this_dir) { |dir_obj| expect(dir_obj).to be_kind_of(VirtFS::VDir) }
499
+ end
500
+
501
+ it "should return the value of the block - when block given" do
502
+ expect(VirtFS::VDir.open(@this_dir) { true }).to be true
503
+ end
504
+ end
505
+ end
506
+ end