/
dir_mirror_spec.rb
65 lines (54 loc) · 1.87 KB
/
dir_mirror_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require "spec_helper"
class Redcar::Project
describe DirMirror do
before do
@dirname = "project_spec_testdir"
@files = {"Carnegie" => "steel",
"Rockefeller" => "oil",
"subdir" => {
"Ford" => "cars"
}}
write_dir_contents(@dirname, @files)
@mirror = DirMirror.new(File.expand_path(@dirname))
end
describe "for a directory" do
it "tells you the directory exists" do
@mirror.exists?.should be_true
end
it "tells you it has changed" do
@mirror.changed?.should be_true
end
describe "top level contents" do
it "the nodes are the contents of the directory" do
top_nodes = @mirror.top
top_nodes.length.should == 3
top_nodes.map {|n| n.text}.should == %w(subdir Carnegie Rockefeller)
end
it "files are leaf nodes" do
top_nodes = @mirror.top
top_nodes.detect {|n| n.text == "Carnegie"}.leaf?.should be_true
top_nodes.detect {|n| n.text == "Rockefeller"}.leaf?.should be_true
end
it "subdirectories are not leaf nodes" do
top_nodes = @mirror.top
top_nodes.detect {|n| n.text == "subdir"}.leaf?.should be_false
end
it "isn't changed after you have got the top nodes" do
@mirror.top
@mirror.changed?.should be_false
end
describe "sub directory contents" do
it "the nodes return their children" do
subdir_node = @mirror.top.detect {|n| n.text == "subdir"}
sub_nodes = subdir_node.children
sub_nodes.length.should == 1
sub_nodes.map {|n| n.text}.should == %w(Ford)
end
end
end
end
after do
FileUtils.rm_r(@dirname)
end
end
end