fast 0.1.3 → 0.1.4
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/.gitignore +1 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +5 -1
- data/README.md +122 -0
- data/fast.gemspec +2 -1
- data/lib/fast.rb +1 -0
- data/lib/fast/dir.rb +73 -35
- data/lib/fast/exceptions.rb +3 -0
- data/lib/fast/fast.rb +3 -0
- data/lib/fast/file.rb +16 -37
- data/lib/fast/filesystemobject.rb +69 -0
- data/lib/fast/version.rb +1 -1
- data/lib/patterns/adapter/fast/dir.rb +19 -0
- data/lib/sub-setter/fast/dir.rb +8 -0
- data/spec/fast/dir_spec.rb +152 -94
- data/spec/fast/file_spec.rb +72 -80
- data/spec/fast/filesystemobject_spec.rb +309 -0
- data/spec/patterns/adapter/fast/dir_spec.rb +16 -0
- data/spec/sub-setter/fast/dir_spec.rb +20 -0
- metadata +47 -10
- data/README.rdoc +0 -81
@@ -0,0 +1,69 @@
|
|
1
|
+
module Fast
|
2
|
+
module FilesystemObject
|
3
|
+
# If a string is passed, returns the same string;
|
4
|
+
# if a symbol is passed, returns the string representation
|
5
|
+
# of the symbol; if an object of the same class as self
|
6
|
+
# is passed, return the #path of that object
|
7
|
+
def normalize path
|
8
|
+
if path.instance_of? String or path.instance_of? Symbol
|
9
|
+
"#{path}"
|
10
|
+
elsif path.instance_of? self.class
|
11
|
+
path.path
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the path to the current FilesystemObject
|
16
|
+
def path
|
17
|
+
@path
|
18
|
+
end
|
19
|
+
|
20
|
+
# Expands the path if it's a relative path
|
21
|
+
def expand path = nil
|
22
|
+
@path = normalize path if path
|
23
|
+
raise Fast::PathNotSettedException, "The path was not setted in this instance" unless @path
|
24
|
+
::File.expand_path @path
|
25
|
+
end
|
26
|
+
|
27
|
+
alias :absolute :expand
|
28
|
+
|
29
|
+
# Returns true if the item exists, false otherwise:
|
30
|
+
# relays on the implementation of a private #do_check?
|
31
|
+
# method in the class that includes the module
|
32
|
+
def exist? path = nil
|
33
|
+
if path
|
34
|
+
path = normalize path
|
35
|
+
@path = path unless @path
|
36
|
+
do_exist? path
|
37
|
+
else
|
38
|
+
raise ArgumentError, "An argument should be provided if this instance has no path setted" unless @path
|
39
|
+
do_exist? @path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
alias :exists? :exist?
|
44
|
+
|
45
|
+
def exist_all? *args
|
46
|
+
unless args.empty?
|
47
|
+
else
|
48
|
+
raise ArgumentError, "An argument should be provided if this instance has no path setted" unless @path
|
49
|
+
do_exist? @path
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def exist_any? *args
|
54
|
+
unless args.empty?
|
55
|
+
else
|
56
|
+
raise ArgumentError, "An argument should be provided if this instance has no path setted" unless @path
|
57
|
+
do_exist? @path
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# Abstract implementation to be overriden in the
|
64
|
+
# actual classes.
|
65
|
+
def do_exist? path
|
66
|
+
raise NotImplementedError, "The implementation of #do_exist? in the module FilesystemObject is abstract, please reimplement in any class including it."
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/fast/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Patterns
|
2
|
+
module Adapter
|
3
|
+
module Fast
|
4
|
+
class Dir
|
5
|
+
def initialize source
|
6
|
+
@source = source
|
7
|
+
end
|
8
|
+
|
9
|
+
def symbols
|
10
|
+
return_me = []
|
11
|
+
@source.each do |entry|
|
12
|
+
return_me.push entry.gsub(/\.(\w+?)$/, "").to_sym
|
13
|
+
end
|
14
|
+
return return_me
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/sub-setter/fast/dir.rb
CHANGED
@@ -15,6 +15,14 @@ module SubSetter
|
|
15
15
|
return_me
|
16
16
|
end
|
17
17
|
|
18
|
+
def ending the_ending
|
19
|
+
return_me = ::Fast::Dir.new
|
20
|
+
@set.each do |entry|
|
21
|
+
return_me << entry if entry.end_with? the_ending
|
22
|
+
end
|
23
|
+
return_me
|
24
|
+
end
|
25
|
+
|
18
26
|
def strip_extension
|
19
27
|
return_me = ::Fast::Dir.new
|
20
28
|
@set.each do |entry|
|
data/spec/fast/dir_spec.rb
CHANGED
@@ -2,14 +2,9 @@ require "fast"
|
|
2
2
|
require "zucker/os"
|
3
3
|
|
4
4
|
describe Fast::Dir do
|
5
|
-
|
6
|
-
context "a Fast::Dir is passed as argument where a path is accepted" do
|
7
|
-
it "should be accepted"
|
8
|
-
|
9
|
-
it "should I really think of a common denominator of Fast::Dir and Fast::File?"
|
10
|
-
end
|
11
|
-
|
12
5
|
shared_examples_for "any dir list" do
|
6
|
+
it "should return a list of Fast::Dir o Fast::File, not strings"
|
7
|
+
|
13
8
|
context "a block is passed as an argument" do
|
14
9
|
it "should pass each entry as argument to the block" do
|
15
10
|
::File.should_not be_directory "demo"
|
@@ -269,6 +264,58 @@ describe Fast::Dir do
|
|
269
264
|
Fast::Dir.new.delete! :alt
|
270
265
|
Fast::Dir.new.delete! :other
|
271
266
|
end
|
267
|
+
|
268
|
+
context "no path is setted and a Hash is passed" do
|
269
|
+
it "build the entire structure in the current dir" do
|
270
|
+
Fast::Dir.new.should_not exist :demo
|
271
|
+
Fast::Dir.new.should_not exist :demo2
|
272
|
+
|
273
|
+
Fast::Dir.new.send @method, {
|
274
|
+
:demo => {
|
275
|
+
:Superfile => "With some content",
|
276
|
+
:subdir => {
|
277
|
+
"deep.txt" => "In the structure."
|
278
|
+
}
|
279
|
+
},
|
280
|
+
:demo2 => {}
|
281
|
+
}
|
282
|
+
|
283
|
+
Fast::File.new.read("demo/Superfile").should == "With some content"
|
284
|
+
Fast::File.new.read("demo/subdir/deep.txt").should == "In the structure."
|
285
|
+
|
286
|
+
Fast::Dir.new.should exist :demo2
|
287
|
+
end
|
288
|
+
|
289
|
+
after do
|
290
|
+
Fast::Dir.new.delete! :demo
|
291
|
+
Fast::Dir.new.delete! :demo2
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
context "a path is setted in the Dir and a Hash is passed" do
|
296
|
+
it "build the entire structure in the right dir" do
|
297
|
+
Fast::Dir.new.should_not exist :demo
|
298
|
+
|
299
|
+
Fast::Dir.new("demo").send @method, {
|
300
|
+
:inner => {
|
301
|
+
:Superfile => "With some content",
|
302
|
+
:subdir => {
|
303
|
+
"deep.txt" => "In the structure."
|
304
|
+
}
|
305
|
+
},
|
306
|
+
:meta => {}
|
307
|
+
}
|
308
|
+
|
309
|
+
Fast::File.new.read("demo/inner/Superfile").should == "With some content"
|
310
|
+
Fast::File.new.read("demo/inner/subdir/deep.txt").should == "In the structure."
|
311
|
+
|
312
|
+
Fast::Dir.new.should exist "demo/meta"
|
313
|
+
end
|
314
|
+
|
315
|
+
after do
|
316
|
+
Fast::Dir.new.delete! :demo
|
317
|
+
end
|
318
|
+
end
|
272
319
|
end
|
273
320
|
|
274
321
|
describe "#create" do
|
@@ -283,6 +330,8 @@ describe Fast::Dir do
|
|
283
330
|
Fast::Dir.new.delete! :demo
|
284
331
|
end
|
285
332
|
|
333
|
+
it "should fail is a Hash is passed an there are conflicts"
|
334
|
+
|
286
335
|
after do
|
287
336
|
Fast::Dir.new.delete! :demo
|
288
337
|
end
|
@@ -299,34 +348,10 @@ describe Fast::Dir do
|
|
299
348
|
}.to_not raise_error ArgumentError, "Dir 'demo' already exists"
|
300
349
|
Fast::Dir.new.delete! :demo
|
301
350
|
end
|
351
|
+
|
352
|
+
it "should override if a Hash is passed and there are conflicts"
|
302
353
|
end
|
303
354
|
|
304
|
-
shared_examples_for "any dir subsetter" do
|
305
|
-
it "should forward self to a subsetter object" do
|
306
|
-
Fast::Dir.new.should_not exist "demo"
|
307
|
-
Fast::File.new.touch "demo/in/subdir.file"
|
308
|
-
|
309
|
-
the_demo_dir = Fast::Dir.new :demo
|
310
|
-
|
311
|
-
SubSetter::Fast::Dir.should_receive( :new ).with the_demo_dir
|
312
|
-
|
313
|
-
the_demo_dir.by
|
314
|
-
|
315
|
-
the_demo_dir.delete!
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
describe "#by" do
|
320
|
-
before :each do @method = :by end
|
321
|
-
it_behaves_like "any dir subsetter"
|
322
|
-
end
|
323
|
-
|
324
|
-
describe "#filter" do
|
325
|
-
before :each do @method = :filter end
|
326
|
-
it_behaves_like "any dir subsetter"
|
327
|
-
end
|
328
|
-
|
329
|
-
|
330
355
|
shared_examples_for "any dir deletion" do
|
331
356
|
it "should delete the directory if it exists" do
|
332
357
|
::File.should_not be_directory "demo"
|
@@ -475,8 +500,37 @@ describe Fast::Dir do
|
|
475
500
|
end
|
476
501
|
end
|
477
502
|
|
503
|
+
# Private method
|
504
|
+
describe "#do_exist?" do
|
505
|
+
context "if the path is a directory" do
|
506
|
+
it "should return true if the passed path is a directory" do
|
507
|
+
::File.should_not be_directory "demo"
|
508
|
+
dir = Fast::Dir.new "demo"
|
509
|
+
dir.create!
|
510
|
+
def dir.call_do_exist?
|
511
|
+
do_exist? "demo"
|
512
|
+
end
|
513
|
+
dir.call_do_exist?.should === true
|
514
|
+
end
|
515
|
+
|
516
|
+
after do
|
517
|
+
Fast::Dir.new.destroy! "demo"
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
it "should return false if the passed path is not a directory" do
|
522
|
+
::File.should_not be_directory "demo"
|
523
|
+
dir = Fast::Dir.new "demo"
|
524
|
+
def dir.call_do_exist?
|
525
|
+
do_exist? "demo"
|
526
|
+
end
|
527
|
+
dir.call_do_exist?.should === false
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
478
531
|
shared_examples_for "any dir existencialism" do
|
479
532
|
it "should return true if the dir exists" do
|
533
|
+
pending "move partially to FilesystemObject"
|
480
534
|
::File.should_not be_directory "demo"
|
481
535
|
Fast::Dir.new.create! "demo"
|
482
536
|
Fast::Dir.new.send( @method, "demo" ).should be_true
|
@@ -484,21 +538,12 @@ describe Fast::Dir do
|
|
484
538
|
end
|
485
539
|
|
486
540
|
it "should return false if the dir does not exist" do
|
541
|
+
pending "move partially to FilesystemObject"
|
487
542
|
::File.should_not be_directory "demo"
|
488
543
|
Fast::Dir.new.send( @method, "demo" ).should be_false
|
489
544
|
end
|
490
545
|
end
|
491
|
-
|
492
|
-
describe "#exist?" do
|
493
|
-
before :each do @method = :exist? end
|
494
|
-
it_behaves_like "any dir existencialism"
|
495
|
-
end
|
496
|
-
|
497
|
-
describe "#exists?" do
|
498
|
-
before :each do @method = :exists? end
|
499
|
-
it_behaves_like "any dir existencialism"
|
500
|
-
end
|
501
|
-
|
546
|
+
|
502
547
|
describe "#exist_all?" do
|
503
548
|
before :each do @method = :exist_all? end
|
504
549
|
it_behaves_like "any dir existencialism"
|
@@ -586,50 +631,6 @@ describe Fast::Dir do
|
|
586
631
|
Fast::Dir.new(:demo).to_s.should include "demo"
|
587
632
|
end
|
588
633
|
end
|
589
|
-
|
590
|
-
shared_examples_for "any dir absolutizer" do
|
591
|
-
context "dir path is a relative route" do
|
592
|
-
it "should expand the dir path with the pwd" do
|
593
|
-
Fast::Dir.new.send( @method, :demo ).should == "#{Dir.pwd}/demo"
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
context "dir path is an absolute route" do
|
598
|
-
it "should return the same path as given" do
|
599
|
-
unless OS.windows?
|
600
|
-
Fast::Dir.new.send( @method, "/dev/null").should == "/dev/null"
|
601
|
-
else
|
602
|
-
pending "POSIX only!"
|
603
|
-
end
|
604
|
-
end
|
605
|
-
end
|
606
|
-
end
|
607
|
-
|
608
|
-
describe "#expand" do
|
609
|
-
before :each do @method = :expand end
|
610
|
-
it_behaves_like "any dir absolutizer"
|
611
|
-
end
|
612
|
-
|
613
|
-
describe "#absolute" do
|
614
|
-
before :each do @method = :absolute end
|
615
|
-
it_behaves_like "any dir absolutizer"
|
616
|
-
end
|
617
|
-
|
618
|
-
describe "#path" do
|
619
|
-
context "the path is setted" do
|
620
|
-
it "should return the path" do
|
621
|
-
the_dir = Fast::Dir.new "demo"
|
622
|
-
the_dir.path.should == "demo"
|
623
|
-
end
|
624
|
-
end
|
625
|
-
|
626
|
-
context "the path is undefined" do
|
627
|
-
it "should return nil" do
|
628
|
-
the_dir = Fast::Dir.new
|
629
|
-
the_dir.path.should be_nil
|
630
|
-
end
|
631
|
-
end
|
632
|
-
end
|
633
634
|
|
634
635
|
shared_examples_for "any dir renaming" do
|
635
636
|
it "should delete current dir and target dir should exist" do
|
@@ -857,13 +858,68 @@ describe Fast::Dir do
|
|
857
858
|
it "should behave like #merge but never fail"
|
858
859
|
end
|
859
860
|
|
860
|
-
describe "#
|
861
|
-
context "
|
862
|
-
|
861
|
+
describe "#conflicts_with?" do
|
862
|
+
context "no directory tree" do
|
863
|
+
context "no file in target has the same name as other in source" do
|
864
|
+
it "should return false" do
|
865
|
+
Fast::Dir.new.should_not exist :target
|
866
|
+
Fast::Dir.new.should_not exist :demo
|
867
|
+
|
868
|
+
Fast::File.new.touch "demo/non_conflict.txt"
|
869
|
+
Fast::File.new.touch "target/not_at_all.txt"
|
870
|
+
|
871
|
+
Fast::Dir.new.conflicts_with?(:demo, :target).should === false
|
872
|
+
end
|
873
|
+
end
|
874
|
+
|
875
|
+
context "at least one file in target has the same name as other in source" do
|
876
|
+
it "should return true" do
|
877
|
+
Fast::Dir.new.should_not exist :target
|
878
|
+
Fast::Dir.new.should_not exist :demo
|
879
|
+
|
880
|
+
Fast::File.new.touch "demo/some_conflict.txt"
|
881
|
+
Fast::File.new.touch "target/some_conflict.txt"
|
882
|
+
Fast::File.new.touch "target/not_at_all.txt"
|
883
|
+
|
884
|
+
Fast::Dir.new.conflicts_with?(:demo, :target).should === true
|
885
|
+
end
|
886
|
+
end
|
863
887
|
end
|
864
|
-
|
865
|
-
context "
|
866
|
-
|
888
|
+
|
889
|
+
context "recursive" do
|
890
|
+
context "no file in any has the same path in the other" do
|
891
|
+
it "should return false" do
|
892
|
+
Fast::Dir.new.should_not exist :demo
|
893
|
+
Fast::Dir.new.should_not exist :target
|
894
|
+
|
895
|
+
Fast::File.new.touch "demo/some/file.txt"
|
896
|
+
Fast::File.new.touch "demo/deep/in/the/tree.file"
|
897
|
+
|
898
|
+
Fast::File.new.touch "target/no/conflict.what"
|
899
|
+
Fast::File.new.touch "target/so/ever.txt"
|
900
|
+
|
901
|
+
Fast::Dir.new.conflicts_with?(:demo, :target).should === false
|
902
|
+
end
|
903
|
+
end
|
904
|
+
|
905
|
+
context "at least one file in target dir have the same path as other in source" do
|
906
|
+
it "should return true" do
|
907
|
+
Fast::Dir.new.should_not exist :demo
|
908
|
+
Fast::Dir.new.should_not exist :target
|
909
|
+
|
910
|
+
Fast::File.new.touch "demo/some/file.txt"
|
911
|
+
Fast::File.new.touch "demo/deep/in/the/tree.file"
|
912
|
+
|
913
|
+
Fast::File.new.touch "target/some/file.txt"
|
914
|
+
Fast::File.new.touch "target/so/ever.txt"
|
915
|
+
|
916
|
+
Fast::Dir.new.conflicts_with?(:demo, :target).should === true
|
917
|
+
end
|
918
|
+
end
|
919
|
+
end
|
920
|
+
|
921
|
+
after do
|
922
|
+
Fast::Dir.new.remove! :demo, :target
|
867
923
|
end
|
868
924
|
end
|
869
925
|
|
@@ -972,6 +1028,8 @@ describe Fast::Dir do
|
|
972
1028
|
Fast::File.new.read("demo/subdir/subsub/other.txt").should include "More than this"
|
973
1029
|
Fast::File.new.read("demo/subdir/demo.txt").should include "Some file content"
|
974
1030
|
end
|
1031
|
+
|
1032
|
+
it "should handle conflicts somehow"
|
975
1033
|
end
|
976
1034
|
|
977
1035
|
after :each do
|
data/spec/fast/file_spec.rb
CHANGED
@@ -5,11 +5,6 @@ require "zucker/os"
|
|
5
5
|
::File.unlink "demo.txt" if ::File.exist? "demo.txt"
|
6
6
|
|
7
7
|
describe Fast::File do
|
8
|
-
|
9
|
-
context "a Fast::File is passed as argument where a path is accepted" do
|
10
|
-
it "should be accepted"
|
11
|
-
end
|
12
|
-
|
13
8
|
shared_examples_for "any file content appending" do
|
14
9
|
it "should create the file if it does not exist" do
|
15
10
|
::File.should_not exist "demo.txt"
|
@@ -384,7 +379,17 @@ describe Fast::File do
|
|
384
379
|
end
|
385
380
|
|
386
381
|
context "a block is passed" do
|
387
|
-
it "should have direct access to file's methods"
|
382
|
+
it "should have direct access to file's methods" do
|
383
|
+
Fast::File.new.should_not exist :demo_txt
|
384
|
+
Fast::File.new.append :demo_txt, "New content!"
|
385
|
+
entered_the_block = false
|
386
|
+
Fast::File.new.read :demo_txt do |the_file|
|
387
|
+
the_file.should be_a ::File
|
388
|
+
entered_the_block = true
|
389
|
+
end
|
390
|
+
entered_the_block.should be_true
|
391
|
+
Fast::File.new.destroy! :demo_txt
|
392
|
+
end
|
388
393
|
end
|
389
394
|
end
|
390
395
|
|
@@ -397,8 +402,39 @@ describe Fast::File do
|
|
397
402
|
end
|
398
403
|
end
|
399
404
|
|
405
|
+
# Private method
|
406
|
+
describe "#do_exist?" do
|
407
|
+
context "it the file exist" do
|
408
|
+
it "should return true" do
|
409
|
+
::File.should_not exist "demo.txt"
|
410
|
+
Fast::File.new.create "demo.txt"
|
411
|
+
file = Fast::File.new "demo.txt"
|
412
|
+
def file.call_do_exist?
|
413
|
+
do_exist? "demo.txt"
|
414
|
+
end
|
415
|
+
file.call_do_exist?.should === true
|
416
|
+
end
|
417
|
+
|
418
|
+
after do
|
419
|
+
Fast::File.new.destroy! "demo.txt"
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
context "if the file does not exist" do
|
424
|
+
it "should return false" do
|
425
|
+
::File.should_not exist "demo.txt"
|
426
|
+
file = Fast::File.new "demo.txt"
|
427
|
+
def file.call_do_exist?
|
428
|
+
do_exist? "demo.txt"
|
429
|
+
end
|
430
|
+
file.call_do_exist?.should === false
|
431
|
+
end
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
400
435
|
shared_examples_for "any file existencialism" do
|
401
436
|
it "should return true if file exists" do
|
437
|
+
pending "move partially to FilesystemObject"
|
402
438
|
::File.should_not exist "demo.file"
|
403
439
|
Fast::File.new.create! "demo.file"
|
404
440
|
Fast::File.new.send( @method, "demo.file" ).should be_true
|
@@ -406,33 +442,26 @@ describe Fast::File do
|
|
406
442
|
end
|
407
443
|
|
408
444
|
it "should return false if file does not exist" do
|
445
|
+
pending "move partially to FilesystemObject"
|
409
446
|
::File.should_not exist "demo.file"
|
410
447
|
Fast::File.new.send( @method, "demo.file" ).should be_false
|
411
448
|
end
|
412
449
|
|
413
450
|
it "should return false if path represents a directory!" do
|
451
|
+
pending "move partially to FilesystemObject"
|
414
452
|
Fast::Dir.new.should_not exist "demo"
|
415
453
|
Fast::Dir.new.create "demo"
|
416
454
|
Fast::File.new.send( @method, "demo" ).should be_false
|
417
455
|
Fast::Dir.new.delete "demo"
|
418
456
|
end
|
419
|
-
end
|
420
|
-
|
421
|
-
describe "#exist?" do
|
422
|
-
before :each do @method = :exist? end
|
423
|
-
it_behaves_like "any file existencialism"
|
424
|
-
end
|
425
|
-
|
426
|
-
describe "#exists?" do
|
427
|
-
before :each do @method = :exists? end
|
428
|
-
it_behaves_like "any file existencialism"
|
429
|
-
end
|
457
|
+
end
|
430
458
|
|
431
459
|
describe "#exist_all?" do
|
432
460
|
before :each do @method = :exist_all? end
|
433
461
|
it_behaves_like "any file existencialism"
|
434
462
|
|
435
463
|
it "should return true if all exist" do
|
464
|
+
pending "Method being moved to Fast::FilesystemObject"
|
436
465
|
# Create the demo files
|
437
466
|
Fast::File.new.touch "demo1.txt", "demo2.txt", "demo3.txt"
|
438
467
|
|
@@ -441,6 +470,7 @@ describe Fast::File do
|
|
441
470
|
end
|
442
471
|
|
443
472
|
it "should return false if any does not exist" do
|
473
|
+
pending "Method being moved to Fast::FilesystemObject"
|
444
474
|
Fast::File.new.touch "demo1.txt", "demo2.txt", "demo3.txt"
|
445
475
|
Fast::File.new.should_not exist "demo4.txt"
|
446
476
|
|
@@ -460,6 +490,7 @@ describe Fast::File do
|
|
460
490
|
it_behaves_like "any file existencialism"
|
461
491
|
|
462
492
|
it "should return true if at least one exists" do
|
493
|
+
pending "Method being moved to Fast::FilesystemObject"
|
463
494
|
Fast::File.new.touch "demo1.txt"
|
464
495
|
Fast::File.new.should_not exist "demo2.txt"
|
465
496
|
|
@@ -467,6 +498,7 @@ describe Fast::File do
|
|
467
498
|
end
|
468
499
|
|
469
500
|
it "should return false if none exist" do
|
501
|
+
pending "Method being moved to Fast::FilesystemObject"
|
470
502
|
Fast::File.new.should_not exist "demo2.txt"
|
471
503
|
Fast::File.new.should_not exist "demo3.txt"
|
472
504
|
|
@@ -480,6 +512,7 @@ describe Fast::File do
|
|
480
512
|
|
481
513
|
describe "#exist_which" do
|
482
514
|
it "should return a list with the files that exist" do
|
515
|
+
pending "Method being moved to Fast::FilesystemObject"
|
483
516
|
Fast::File.new.should_not exist "demo1.txt"
|
484
517
|
Fast::File.new.should_not exist "demo2.txt"
|
485
518
|
Fast::File.new.should_not exist "demo3.txt"
|
@@ -522,25 +555,6 @@ describe Fast::File do
|
|
522
555
|
Fast::File.new.delete! "demo.txt"
|
523
556
|
end
|
524
557
|
end
|
525
|
-
|
526
|
-
shared_examples_for "any file subsetter" do
|
527
|
-
# SubSetter as described in http://xaviervia.com.ar/patterns/sub-setter
|
528
|
-
it "should forward self to a filtering object" do
|
529
|
-
the_demo_file = Fast::File.new :demo
|
530
|
-
SubSetter::Fast::File.should_receive( :new ).with the_demo_file
|
531
|
-
the_demo_file.by
|
532
|
-
end
|
533
|
-
end
|
534
|
-
|
535
|
-
describe "#by" do
|
536
|
-
before :each do @method = :by end
|
537
|
-
it_behaves_like "any file subsetter"
|
538
|
-
end
|
539
|
-
|
540
|
-
describe "#filter" do
|
541
|
-
before :each do @method = :filter end
|
542
|
-
it_behaves_like "any file subsetter"
|
543
|
-
end
|
544
558
|
|
545
559
|
describe ".new" do
|
546
560
|
it "should accept a string path as argument" do
|
@@ -552,50 +566,6 @@ describe Fast::File do
|
|
552
566
|
end
|
553
567
|
end
|
554
568
|
|
555
|
-
shared_examples_for "any file absolutizer" do
|
556
|
-
context "file path is a relative route" do
|
557
|
-
it "should expand the file path with pwd" do
|
558
|
-
Fast::File.new.send( @method, "demo.file" ).should == "#{Dir.pwd}/demo.file"
|
559
|
-
end
|
560
|
-
end
|
561
|
-
|
562
|
-
context "file path is an absolute route" do
|
563
|
-
it "should return the same as given path" do
|
564
|
-
unless OS.windows?
|
565
|
-
Fast::File.new.send( @method, "/dev/null" ).should == "/dev/null"
|
566
|
-
else
|
567
|
-
pending "POSIX only!"
|
568
|
-
end
|
569
|
-
end
|
570
|
-
end
|
571
|
-
end
|
572
|
-
|
573
|
-
describe "#expand" do
|
574
|
-
before :each do @method = :expand end
|
575
|
-
it_behaves_like "any file absolutizer"
|
576
|
-
end
|
577
|
-
|
578
|
-
describe "#absolute" do
|
579
|
-
before :each do @method = :absolute end
|
580
|
-
it_behaves_like "any file absolutizer"
|
581
|
-
end
|
582
|
-
|
583
|
-
describe "#path" do
|
584
|
-
context "the path is setted" do
|
585
|
-
it "returns the path" do
|
586
|
-
the_file = Fast::File.new "demo.file"
|
587
|
-
the_file.path.should == "demo.file"
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
|
-
context "the path is undefined" do
|
592
|
-
it "returns nil" do
|
593
|
-
the_file = Fast::File.new
|
594
|
-
the_file.path.should be_nil
|
595
|
-
end
|
596
|
-
end
|
597
|
-
end
|
598
|
-
|
599
569
|
shared_examples_for "any file renaming" do
|
600
570
|
it "should change the file's name" do
|
601
571
|
Fast::File.new.should_not exist "demo.file"
|
@@ -798,4 +768,26 @@ describe Fast::File do
|
|
798
768
|
end
|
799
769
|
end
|
800
770
|
end
|
771
|
+
|
772
|
+
describe "#extension" do
|
773
|
+
context "a path is setted and it has extension" do
|
774
|
+
it "should return the extension"
|
775
|
+
end
|
776
|
+
|
777
|
+
context "a path is setted but has no extension" do
|
778
|
+
it "should return nil"
|
779
|
+
end
|
780
|
+
|
781
|
+
context "a path is sent in the call and has extension" do
|
782
|
+
it "should return the extension"
|
783
|
+
end
|
784
|
+
|
785
|
+
context "a path is sent in the call but has no extension" do
|
786
|
+
it "should return nil"
|
787
|
+
end
|
788
|
+
|
789
|
+
context "no path setted" do
|
790
|
+
it "should raise exception"
|
791
|
+
end
|
792
|
+
end
|
801
793
|
end
|