This repository was archived by the owner on Mar 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfind_spec.rb
86 lines (71 loc) · 2.27 KB
/
find_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
describe "#find" do
# This is the node structure we'll be using for testing:
#
# root
# +-- foo
# +-- bar
# +-- baz
#
let!(:root) { node "/" }
let!(:foo) { node "foo", parent: root }
let!(:bar) { node "bar", parent: root }
let!(:baz) { node "baz.html", parent: bar }
# add a secret folder with some equally secret data
let!(:secret) { node "_secret", parent: root }
let!(:data) { node "data", parent: secret }
specify "normal singular expressions" do
expect(root.find("foo")).to eq(foo)
expect(root.find("bar")).to eq(bar)
end
specify "expressions starting with slash" do
# Just a slash will always return root
expect(root.find("/")).to eq(root)
expect(baz.find("/")).to eq(root)
# Expressions starting with a slash will start at root
expect(baz.find("/foo")).to eq(foo)
expect(baz.find("/bar/baz")).to eq(baz)
end
specify "find(.) returns the parent" do
expect(baz.find(".")).to eq(bar)
expect(baz.find("./")).to eq(bar)
end
specify "find(..) returns the parent's parent" do
expect(baz.find("..")).to eq(root)
expect(baz.find("../")).to eq(root)
end
specify "crazy mixed expressions" do
expect(baz.find("../foo")).to eq(foo)
expect(baz.find("../foo/../bar/baz")).to eq(baz)
end
specify "reduce duplicate slashes" do
expect(baz.find("..//bar")).to eq(bar)
end
specify "not found" do
expect(root.find("moo")).to eq(nil)
end
specify "faulty expressions" do
expect(root.find(" haha lol zomg ")).to eq(nil)
end
specify "with or without extensions" do
expect(bar.find("baz")).to eq(baz)
expect(bar.find("baz.html")).to eq(baz)
expect(bar.find("baz.txt")).to eq(nil)
end
describe "private vs. public nodes" do
specify "by default, finds within private nodes" do
expect(root.find("_secret/data")).to eq(data)
end
context "with public_only set to true" do
specify "it does not find private nodes" do
expect(root.find("_secret/data", public_only: true)).to eq(nil)
end
end
end
describe "#find!" do
context "when using an invalid path" do
it "raises an error" do
expect { root.find!("invalid") }.to raise_error(%{Could not find node for path expression 'invalid'})
end
end
end
end