valise 0.3
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/doc/README +69 -0
- data/doc/Specification +72 -0
- data/doc/Specifications +81 -0
- data/doc/coverage/assets/0.5.3/app.js +88 -0
- data/doc/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
- data/doc/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +363 -0
- data/doc/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
- data/doc/coverage/assets/0.5.3/favicon_green.png +0 -0
- data/doc/coverage/assets/0.5.3/favicon_red.png +0 -0
- data/doc/coverage/assets/0.5.3/favicon_yellow.png +0 -0
- data/doc/coverage/assets/0.5.3/highlight.css +129 -0
- data/doc/coverage/assets/0.5.3/highlight.pack.js +1 -0
- data/doc/coverage/assets/0.5.3/jquery-1.6.2.min.js +18 -0
- data/doc/coverage/assets/0.5.3/jquery.dataTables.min.js +152 -0
- data/doc/coverage/assets/0.5.3/jquery.timeago.js +141 -0
- data/doc/coverage/assets/0.5.3/jquery.url.js +174 -0
- data/doc/coverage/assets/0.5.3/loading.gif +0 -0
- data/doc/coverage/assets/0.5.3/magnify.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/doc/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +295 -0
- data/doc/coverage/assets/0.5.3/stylesheet.css +383 -0
- data/doc/coverage/index.html +5843 -0
- data/doc/coverage/jquery-1.3.2.min.js +19 -0
- data/doc/coverage/jquery.tablesorter.min.js +15 -0
- data/doc/coverage/lib-fileset-errors_rb.html +231 -0
- data/doc/coverage/lib-fileset-item_rb.html +303 -0
- data/doc/coverage/lib-fileset-populator_rb.html +249 -0
- data/doc/coverage/lib-fileset-search-root_rb.html +1053 -0
- data/doc/coverage/lib-fileset-utils_rb.html +453 -0
- data/doc/coverage/lib-fileset_rb.html +789 -0
- data/doc/coverage/print.css +12 -0
- data/doc/coverage/rcov.js +42 -0
- data/doc/coverage/screen.css +270 -0
- data/lib/valise/errors.rb +30 -0
- data/lib/valise/item.rb +105 -0
- data/lib/valise/path-matcher.rb +113 -0
- data/lib/valise/search-root.rb +166 -0
- data/lib/valise/stack.rb +169 -0
- data/lib/valise/stem-decorator.rb +56 -0
- data/lib/valise/utils.rb +65 -0
- data/lib/valise.rb +219 -0
- data/spec/addable.rb +41 -0
- data/spec/dump_load.rb +32 -0
- data/spec/error_handling.rb +9 -0
- data/spec/fileset.rb +170 -0
- data/spec/glob_handling.rb +28 -0
- data/spec/item.rb +35 -0
- data/spec/merge_diff.rb +93 -0
- data/spec/population.rb +51 -0
- data/spec/search_root.rb +24 -0
- data/spec/stemming.rb +33 -0
- data/spec_help/file-sandbox.rb +164 -0
- data/spec_help/gem_test_suite.rb +17 -0
- data/spec_help/spec_helper.rb +3 -0
- data/spec_help/ungemmer.rb +37 -0
- metadata +220 -0
data/spec/dump_load.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'valise'
|
|
2
|
+
require 'file-sandbox'
|
|
3
|
+
|
|
4
|
+
describe Valise do
|
|
5
|
+
include FileSandbox
|
|
6
|
+
|
|
7
|
+
let :valise do
|
|
8
|
+
sandbox.new :directory => "base/test"
|
|
9
|
+
Valise::Set.define do
|
|
10
|
+
handle "test/yaml-file", :yaml
|
|
11
|
+
rw "base"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let :item do
|
|
16
|
+
valise.get("test/yaml-file").first
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should store data as YAML" do
|
|
20
|
+
item.contents = { :a => "test hash" }
|
|
21
|
+
item.save
|
|
22
|
+
YAML::load( File::read(item.full_path)).should == { :a => "test hash" }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should load data from YAML" do
|
|
26
|
+
File::open(item.full_path, "w") do |file|
|
|
27
|
+
file.write(YAML::dump( :another => "test hash" ))
|
|
28
|
+
end
|
|
29
|
+
item.contents.should == {:another => "test hash"}
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'valise'
|
|
2
|
+
|
|
3
|
+
describe Valise, "error conditions" do
|
|
4
|
+
describe "HandlerCollision is raised" do
|
|
5
|
+
it "when a file handler collides from the same path"
|
|
6
|
+
it "when a file handler collides with a glob path"
|
|
7
|
+
it "when two Valises are added with a handler for the same path"
|
|
8
|
+
end
|
|
9
|
+
end
|
data/spec/fileset.rb
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
require 'valise'
|
|
2
|
+
require 'file-sandbox'
|
|
3
|
+
|
|
4
|
+
describe Valise, "error cases" do
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
describe Valise do
|
|
8
|
+
include FileSandbox
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
sandbox.new :directory => "etc/conductor"
|
|
12
|
+
sandbox.new :directory => "home/.conductor"
|
|
13
|
+
sandbox.new :directory => ".conductor"
|
|
14
|
+
sandbox.new :directory => "spec"
|
|
15
|
+
sandbox.new :file => "home/.conductor/existed", :with_contents => "TEST"
|
|
16
|
+
@valise = Valise::Set.define do
|
|
17
|
+
rw ".conductor"
|
|
18
|
+
rw "home/.conductor"
|
|
19
|
+
rw "etc/conductor"
|
|
20
|
+
defaults do
|
|
21
|
+
file :text, align(<<-EOT)
|
|
22
|
+
<<<
|
|
23
|
+
Some text
|
|
24
|
+
EOT
|
|
25
|
+
|
|
26
|
+
dir "nest" do
|
|
27
|
+
file "egg", "yolk"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should be a Valise::Set" do
|
|
34
|
+
@valise.should be_an_instance_of(Valise::Set)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "retrieving files" do
|
|
38
|
+
it "should get default text files" do
|
|
39
|
+
@valise.find("text").contents.should == "Some text"
|
|
40
|
+
@valise.find(:text).contents.should == "Some text"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should get text files from library files" do
|
|
44
|
+
@valise.find("existed").contents.should == "TEST"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "should get default nested files" do
|
|
48
|
+
@valise.find(%w{nest egg}).contents.should == "yolk"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should get text files from filesystem" do
|
|
52
|
+
sandbox.new :file => "home/.conductor/text", :with_contents => "Other text"
|
|
53
|
+
@valise.find(:text).contents.should == "Other text"
|
|
54
|
+
@valise.find("text").contents.should == "Other text"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# it "should get yaml files named with strings" do
|
|
58
|
+
# @valise.find(:yaml).contents.should == {:one => 1}
|
|
59
|
+
# @valise.find("yaml").contents.should == {:one => 1}
|
|
60
|
+
# end
|
|
61
|
+
|
|
62
|
+
# it "should get yaml files from the filesystem" do
|
|
63
|
+
# sandbox.new :file => "home/.conductor/yaml", :with_contents => "--- \n- Coo\n"
|
|
64
|
+
# @valise.find(:yaml).contents.should == ["Coo"]
|
|
65
|
+
# @valise.find("yaml").contents.should == ["Coo"]
|
|
66
|
+
# end
|
|
67
|
+
|
|
68
|
+
# it "should get yaml files named with symbols" do
|
|
69
|
+
# @valise.find(:other).contents.should == [3,4,5]
|
|
70
|
+
# @valise.find("other").contents.should == [3,4,5]
|
|
71
|
+
# end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
share_examples_for "a populating Valise" do
|
|
75
|
+
it "should create files on populate" do
|
|
76
|
+
pending
|
|
77
|
+
|
|
78
|
+
@valise.populate
|
|
79
|
+
|
|
80
|
+
sandbox["etc/conductor/tool_configs"].should exist
|
|
81
|
+
sandbox["home/.conductor/tool_configs"].should exist
|
|
82
|
+
sandbox[".conductor/tool_configs"].should exist
|
|
83
|
+
sandbox[".conductor/tool_configs/test"].should exist
|
|
84
|
+
sandbox[".conductor/tool_configs/test"].contents.should == "TEST"
|
|
85
|
+
sandbox["etc/conductor/tool_configs/test"].should_not exist
|
|
86
|
+
sandbox["home/.conductor/tool_configs/test"].should_not exist
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "should not clobber existing files in populate" do
|
|
90
|
+
pending
|
|
91
|
+
sandbox.new :file => ".conductor/tool_configs/test", :with_contents => "not test"
|
|
92
|
+
|
|
93
|
+
@valise.populate
|
|
94
|
+
|
|
95
|
+
sandbox["etc/conductor/tool_configs"].should exist
|
|
96
|
+
sandbox["home/.conductor/tool_configs"].should exist
|
|
97
|
+
sandbox[".conductor/tool_configs"].should exist
|
|
98
|
+
sandbox[".conductor/tool_configs/test"].should exist
|
|
99
|
+
sandbox[".conductor/tool_configs/test"].contents.should == "not test"
|
|
100
|
+
sandbox["etc/conductor/tool_configs/test"].should_not exist
|
|
101
|
+
sandbox["home/.conductor/tool_configs/test"].should_not exist
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should allow empty directory definition" do
|
|
106
|
+
pending
|
|
107
|
+
@valise.populate
|
|
108
|
+
|
|
109
|
+
sandbox["etc/conductor/empty"].should exist
|
|
110
|
+
sandbox[".conductor/empty"].should exist
|
|
111
|
+
sandbox["home/.conductor/empty"].should exist
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "should get files once populated" do
|
|
115
|
+
pending
|
|
116
|
+
@valise.populate
|
|
117
|
+
|
|
118
|
+
file = @valise.get_file(%w{tool_configs test})
|
|
119
|
+
|
|
120
|
+
file.contents.should == "TEST"
|
|
121
|
+
file.contents = "not test"
|
|
122
|
+
file.store
|
|
123
|
+
|
|
124
|
+
file2 = @valise.get_file(%w{tool_configs test})
|
|
125
|
+
file2.contents.should == "not test"
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
if false
|
|
130
|
+
describe "defined with the DSL" do
|
|
131
|
+
#it_should_behave_like "a populating Valise"
|
|
132
|
+
|
|
133
|
+
before do
|
|
134
|
+
@valise.define do
|
|
135
|
+
dir "tool_configs" do
|
|
136
|
+
file "test", "TEST"
|
|
137
|
+
end
|
|
138
|
+
dir "empty"
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
describe "defined programmatically" do
|
|
144
|
+
it_should_behave_like "a populating Valise"
|
|
145
|
+
|
|
146
|
+
before do
|
|
147
|
+
@valise.add_file(%w{tool_configs test}, "TEST")
|
|
148
|
+
@valise.add_dir(%w{empty})
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
describe Valise, " - the unpath method: " do
|
|
155
|
+
before do
|
|
156
|
+
@search_root = Valise::SearchRoot.new("")
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it 'state => ["state"]' do
|
|
160
|
+
@search_root.unpath("state").should == %w{state}
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it 'a File => #path' do
|
|
164
|
+
@file = File.new(__FILE__)
|
|
165
|
+
@path = __FILE__.split("/")
|
|
166
|
+
@search_root.unpath(@file)
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'valise'
|
|
2
|
+
require 'file-sandbox'
|
|
3
|
+
|
|
4
|
+
describe Valise, "glob handling" do
|
|
5
|
+
include FileSandbox
|
|
6
|
+
|
|
7
|
+
let :valise do
|
|
8
|
+
sandbox.new :directory => "base/test"
|
|
9
|
+
Valise::Set.define do
|
|
10
|
+
handle "test/full", :yaml
|
|
11
|
+
handle "**/*.file", :yaml
|
|
12
|
+
handle "path/*.path", :yaml
|
|
13
|
+
rw "base"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should recognize based on a full path" do
|
|
18
|
+
valise.serialization("test/full").should == Valise::Serialization::YAML
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should recognize base on a file glob" do
|
|
22
|
+
valise.serialization("test/by.file").should == Valise::Serialization::YAML
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should recognize based on a path glob" do
|
|
26
|
+
valise.serialization("path/by.path").should == Valise::Serialization::YAML
|
|
27
|
+
end
|
|
28
|
+
end
|
data/spec/item.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'valise'
|
|
2
|
+
require 'file-sandbox'
|
|
3
|
+
|
|
4
|
+
describe "Invidual items in the set" do
|
|
5
|
+
include FileSandbox
|
|
6
|
+
let (:root_path) do
|
|
7
|
+
sandbox.new :directory => "root"
|
|
8
|
+
sandbox.new :file => "root/item", :with_contents => "testing"
|
|
9
|
+
"root"
|
|
10
|
+
end
|
|
11
|
+
let (:set) do
|
|
12
|
+
path = root_path
|
|
13
|
+
Valise::Set.define do
|
|
14
|
+
rw path
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
subject { set.find("item") }
|
|
19
|
+
|
|
20
|
+
its (:full_path) { should == "root/item" }
|
|
21
|
+
|
|
22
|
+
describe "#contents=" do
|
|
23
|
+
its (:contents) { should == "testing" }
|
|
24
|
+
|
|
25
|
+
it "raw_file" do
|
|
26
|
+
subject.raw_file.path.should == "root/item"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should make contents available" do
|
|
30
|
+
subject.open do |file|
|
|
31
|
+
file.read.should == "testing"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/spec/merge_diff.rb
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
require 'valise'
|
|
2
|
+
require 'file-sandbox'
|
|
3
|
+
|
|
4
|
+
describe Valise do
|
|
5
|
+
include FileSandbox
|
|
6
|
+
|
|
7
|
+
let :bottom_hash do
|
|
8
|
+
{}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
let :middle_hash do
|
|
12
|
+
{}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let :top_hash do
|
|
16
|
+
{}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
let :valise do
|
|
21
|
+
sandbox.new :directory => "base/test"
|
|
22
|
+
sandbox.new :directory => "layer2/test"
|
|
23
|
+
sandbox.new :directory => "layer3/test"
|
|
24
|
+
sandbox.new :file => "base/test/file", :with_contents => YAML::dump(bottom_hash)
|
|
25
|
+
sandbox.new :file => "layer2/test/file", :with_contents => YAML::dump(middle_hash)
|
|
26
|
+
sandbox.new :file => "layer3/test/file", :with_contents => YAML::dump(top_hash)
|
|
27
|
+
|
|
28
|
+
Valise::Set.define do
|
|
29
|
+
handle "test/file", :yaml, :hash_merge
|
|
30
|
+
rw "layer3"
|
|
31
|
+
rw "layer2"
|
|
32
|
+
rw "base"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
let :item do
|
|
37
|
+
valise.get("test/file").first
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "merge" do
|
|
41
|
+
it "should merge values from the bottom" do
|
|
42
|
+
bottom_hash[:a] = 3
|
|
43
|
+
item.contents.should == {:a => 3}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should obscure values from lower down" do
|
|
47
|
+
bottom_hash[:a] = 3
|
|
48
|
+
middle_hash[:a] = 1
|
|
49
|
+
item.contents.should == {:a => 1}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should prefer topmost value" do
|
|
53
|
+
bottom_hash[:a] = 3
|
|
54
|
+
middle_hash[:a] = 2
|
|
55
|
+
top_hash[:a] = 1
|
|
56
|
+
|
|
57
|
+
item.contents.should == {:a => 1}
|
|
58
|
+
item.stack.map{|stack| stack.contents[:a]}.should == [1,2,3]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should prefer top nil to bottom value" do
|
|
62
|
+
bottom_hash[:a] = 3
|
|
63
|
+
top_hash[:a] = nil
|
|
64
|
+
item.contents[:a].should == nil
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should do a deep merge" do
|
|
68
|
+
bottom_hash[:a] = {:a => {:a => 3}}
|
|
69
|
+
middle_hash[:a] = {:a => {:a => 2}}
|
|
70
|
+
top_hash[:a] = {:a => {:a => 1}}
|
|
71
|
+
|
|
72
|
+
item.stack.map{|stack| stack.contents[:a][:a][:a]}.should == [1,2,3]
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "diff" do
|
|
77
|
+
before :each do
|
|
78
|
+
bottom_hash.merge!(:a => 1, :b => 2, :c => "bad")
|
|
79
|
+
top_hash.merge!(:a => 2, :b => 7)
|
|
80
|
+
item.contents = {:a => 1, :b => 3}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should reduce actual contents of an item to minimal" do
|
|
84
|
+
item.contents[:a].should == 1
|
|
85
|
+
item.load_contents[:a].should be_nil
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should mask missing keys" do
|
|
89
|
+
item.contents[:c].should be_nil
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
data/spec/population.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'valise'
|
|
2
|
+
require 'file-sandbox'
|
|
3
|
+
|
|
4
|
+
describe Valise do
|
|
5
|
+
include FileSandbox
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
sandbox.new :directory => "etc/conductor"
|
|
9
|
+
sandbox.new :directory => "home/.conductor"
|
|
10
|
+
sandbox.new :directory => ".conductor"
|
|
11
|
+
sandbox.new :directory => "spec"
|
|
12
|
+
sandbox.new :file => "home/.conductor/existed", :with_contents => "TEST"
|
|
13
|
+
|
|
14
|
+
@from = Valise::Set.define do
|
|
15
|
+
ro "home/.conductor"
|
|
16
|
+
|
|
17
|
+
defaults do
|
|
18
|
+
file :egg, "yolk"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@to = Valise::Set.define do
|
|
23
|
+
rw ".conductor"
|
|
24
|
+
rw "etc/conductor"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "population" do
|
|
29
|
+
before do
|
|
30
|
+
@from.populate(@to)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should populate successfully" do
|
|
34
|
+
@to.find("egg").contents.should == "yolk"
|
|
35
|
+
@to.find("existed").contents.should == "TEST"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "reverse population" do
|
|
40
|
+
before do
|
|
41
|
+
@from.populate(@to) do |stack|
|
|
42
|
+
stack.reverse
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should populate successfully" do
|
|
47
|
+
@to.find("egg").contents.should == "yolk"
|
|
48
|
+
@to.find("existed").contents.should == "TEST"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/spec/search_root.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'file-sandbox'
|
|
3
|
+
require 'valise/search-root'
|
|
4
|
+
|
|
5
|
+
describe Valise::SearchRoot do
|
|
6
|
+
include FileSandbox
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
sandbox.new :directory => "test"
|
|
10
|
+
sandbox.new :file => "test/file", :with_contents => "TEST"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let :search_root do
|
|
14
|
+
Valise::SearchRoot.new("test")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should find a file in the root" do
|
|
18
|
+
search_root.present?(%w{file}).should be_true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should raise PathNotInRoot if path isn't in root" do
|
|
22
|
+
search_root.present?(%w{nothere}).should be_false
|
|
23
|
+
end
|
|
24
|
+
end
|
data/spec/stemming.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'valise'
|
|
2
|
+
require 'file-sandbox'
|
|
3
|
+
|
|
4
|
+
describe Valise, "with stemming" do
|
|
5
|
+
include FileSandbox
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
sandbox.new :directory => "conductor"
|
|
9
|
+
sandbox.new :directory => "other_dir"
|
|
10
|
+
sandbox.new :file => "conductor/top", :with_contents => "conductor/exists"
|
|
11
|
+
sandbox.new :file => "other_dir/middle", :with_contents => "other_dir/exists"
|
|
12
|
+
|
|
13
|
+
@valise = Valise::Set.define do
|
|
14
|
+
stemmed("stem").rw("conductor")
|
|
15
|
+
stemmed("stem") do
|
|
16
|
+
rw "other_dir"
|
|
17
|
+
end
|
|
18
|
+
rw "conductor"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should find a file in a stemed dir" do
|
|
23
|
+
@valise.find("stem/top").contents.should == "conductor/exists"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should find a file in a stemed dir defined in a block" do
|
|
27
|
+
@valise.find("stem/middle").contents.should == "other_dir/exists"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should find a file in a normal dir behind stemming" do
|
|
31
|
+
@valise.find("top").contents.should == "conductor/exists"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#require 'ftools'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
|
|
4
|
+
module FileSandbox
|
|
5
|
+
def self.included(spec)
|
|
6
|
+
return unless spec.respond_to? :before
|
|
7
|
+
|
|
8
|
+
spec.before do
|
|
9
|
+
setup_sandbox
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
spec.after do
|
|
13
|
+
teardown_sandbox
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class HaveContents
|
|
18
|
+
def initialize(contents)
|
|
19
|
+
@contents = contents
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def matches?(target)
|
|
23
|
+
case @contents
|
|
24
|
+
when Regexp
|
|
25
|
+
@contents =~ target.contents
|
|
26
|
+
when String
|
|
27
|
+
@contents == target.contents
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def have_contents(expected)
|
|
33
|
+
HaveContents.new(expected)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
attr_reader :sandbox
|
|
37
|
+
|
|
38
|
+
def in_sandbox(&block)
|
|
39
|
+
raise "I expected to create a sandbox as you passed in a block to me" if !block_given?
|
|
40
|
+
|
|
41
|
+
setup_sandbox
|
|
42
|
+
original_error = nil
|
|
43
|
+
|
|
44
|
+
begin
|
|
45
|
+
yield @sandbox
|
|
46
|
+
rescue => e
|
|
47
|
+
original_error = e
|
|
48
|
+
raise
|
|
49
|
+
ensure
|
|
50
|
+
begin
|
|
51
|
+
teardown_sandbox
|
|
52
|
+
rescue
|
|
53
|
+
if original_error
|
|
54
|
+
STDERR.puts "ALERT: a test raised an error and failed to release some lock(s) in the sandbox directory"
|
|
55
|
+
raise(original_error)
|
|
56
|
+
else
|
|
57
|
+
raise
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def setup_sandbox(path = '__sandbox')
|
|
64
|
+
unless @sandbox
|
|
65
|
+
@sandbox = Sandbox.new(path)
|
|
66
|
+
@__old_path_for_sandbox = Dir.pwd
|
|
67
|
+
Dir.chdir(@sandbox.root)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def teardown_sandbox
|
|
72
|
+
if @sandbox
|
|
73
|
+
Dir.chdir(@__old_path_for_sandbox)
|
|
74
|
+
@sandbox.clean_up
|
|
75
|
+
@sandbox = nil
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
class Sandbox
|
|
80
|
+
attr_reader :root
|
|
81
|
+
|
|
82
|
+
def initialize(path = '__sandbox')
|
|
83
|
+
@root = File.expand_path(path)
|
|
84
|
+
clean_up
|
|
85
|
+
FileUtils.mkdir_p @root
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def [](name)
|
|
89
|
+
SandboxFile.new(File.join(@root, name), name)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# usage new :file=>'my file.rb', :with_contents=>'some stuff'
|
|
93
|
+
def new(options)
|
|
94
|
+
if options.has_key? :directory
|
|
95
|
+
dir = self[options.delete(:directory)]
|
|
96
|
+
FileUtils.mkdir_p dir.path
|
|
97
|
+
else
|
|
98
|
+
file = self[options.delete(:file)]
|
|
99
|
+
if (binary_content = options.delete(:with_binary_content) || options.delete(:with_binary_contents))
|
|
100
|
+
file.binary_content = binary_content
|
|
101
|
+
else
|
|
102
|
+
file.content = (options.delete(:with_content) || options.delete(:with_contents) || '')
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
raise "unexpected keys '#{options.keys.join(', ')}'" unless options.empty?
|
|
107
|
+
|
|
108
|
+
dir || file
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def remove(options)
|
|
112
|
+
name = File.join(@root, options[:file])
|
|
113
|
+
FileUtils.remove_file name
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def clean_up
|
|
117
|
+
FileUtils.rm_rf @root
|
|
118
|
+
if File.exists? @root
|
|
119
|
+
raise "Could not remove directory #{@root.inspect}, something is probably still holding a lock on it"
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class SandboxFile
|
|
126
|
+
attr_reader :path
|
|
127
|
+
|
|
128
|
+
def initialize(path, sandbox_path)
|
|
129
|
+
@path = path
|
|
130
|
+
@sandbox_path = sandbox_path
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def inspect
|
|
134
|
+
"SandboxFile: #@sandbox_path"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def exist?
|
|
138
|
+
File.exist? path
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def content
|
|
142
|
+
File.read path
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def content=(content)
|
|
146
|
+
FileUtils.mkdir_p File.dirname(@path)
|
|
147
|
+
File.open(@path, "w") {|f| f << content}
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def binary_content=(content)
|
|
151
|
+
FileUtils.mkdir_p File.dirname(@path)
|
|
152
|
+
File.open(@path, "wb") {|f| f << content}
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def create
|
|
156
|
+
self.content = ''
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
alias exists? exist?
|
|
160
|
+
alias contents content
|
|
161
|
+
alias contents= content=
|
|
162
|
+
alias binary_contents= binary_content=
|
|
163
|
+
end
|
|
164
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
puts Dir::pwd
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
begin
|
|
4
|
+
require 'spec'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
false
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class RSpecTest < Test::Unit::TestCase
|
|
10
|
+
def test_that_rspec_is_available
|
|
11
|
+
assert_nothing_raised("\n\n * RSpec isn't available - please run: gem install rspec *\n\n"){ ::Spec }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_that_specs_pass
|
|
15
|
+
assert(system(*%w{spec -f e -p **/*.rb spec}),"\n\n * Specs failed *\n\n")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class Ungemmer
|
|
2
|
+
def self.ungem(*names)
|
|
3
|
+
return
|
|
4
|
+
deps = names.map do |name|
|
|
5
|
+
Gem::Dependency.new(name, nil)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
deps.each do |dep|
|
|
9
|
+
Gem.source_index.search(dep).each do |gemspec|
|
|
10
|
+
puts " ** Ungemming #{gemspec.full_name} **"
|
|
11
|
+
Gem.source_index.remove_spec(gemspec.full_name)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Gem.instance_eval do
|
|
16
|
+
if defined? Gem::MUTEX
|
|
17
|
+
Gem::MUTEX.synchronize do
|
|
18
|
+
@searcher = nil
|
|
19
|
+
end
|
|
20
|
+
else
|
|
21
|
+
@searcher = nil
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.ungem_gemspec
|
|
27
|
+
Dir[File::expand_path(__FILE__ + "../../../*.gemspec")].each do |gemspec_path|
|
|
28
|
+
puts "Ungemming based on #{gemspec_path}"
|
|
29
|
+
begin
|
|
30
|
+
spec = Gem::Specification::load(gemspec_path)
|
|
31
|
+
Ungemmer::ungem(spec)
|
|
32
|
+
rescue LoadError
|
|
33
|
+
puts "Couldn't load #{gemspec_path}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|