vfs 0.3.12 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vfs.rb +5 -5
- data/lib/vfs/entries/dir.rb +65 -65
- data/lib/vfs/entries/entry.rb +38 -38
- data/lib/vfs/entries/entry/special_attributes.rb +2 -2
- data/lib/vfs/entries/file.rb +46 -46
- data/lib/vfs/entries/universal_entry.rb +5 -5
- data/lib/vfs/entry_proxy.rb +10 -10
- data/lib/vfs/integration/string.rb +4 -4
- data/lib/vfs/path.rb +25 -25
- data/lib/vfs/storages/local.rb +29 -29
- data/lib/vfs/storages/specification.rb +27 -27
- data/lib/vfs/vfs.rb +7 -7
- data/readme.md +14 -35
- data/spec/container_spec.rb +5 -5
- data/spec/dir_spec.rb +49 -49
- data/spec/entry_spec.rb +9 -9
- data/spec/file_spec.rb +47 -47
- data/spec/path_spec.rb +31 -31
- data/spec/spec_helper.rb +11 -11
- data/spec/storages/local_spec.rb +4 -4
- data/spec/universal_entry_spec.rb +9 -9
- metadata +1 -1
data/spec/entry_spec.rb
CHANGED
@@ -2,19 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Entry' do
|
4
4
|
with_test_fs
|
5
|
-
|
5
|
+
|
6
6
|
before do
|
7
7
|
@path = test_fs['a/b/c']
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "name" do
|
11
11
|
@path.name.should == 'c'
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it 'tmp' do
|
15
15
|
tmp = test_fs.tmp
|
16
16
|
tmp.should be_dir
|
17
|
-
|
17
|
+
|
18
18
|
tmp = nil
|
19
19
|
test_fs.tmp do |path|
|
20
20
|
tmp = path
|
@@ -22,16 +22,16 @@ describe 'Entry' do
|
|
22
22
|
end
|
23
23
|
tmp.should_not exist
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it 'should respond to local?'
|
27
|
-
|
27
|
+
|
28
28
|
it 'should respond to host'
|
29
|
-
|
29
|
+
|
30
30
|
describe 'attributes' do
|
31
31
|
it 'created_at'
|
32
|
-
|
32
|
+
|
33
33
|
it 'updated_at'
|
34
|
-
|
34
|
+
|
35
35
|
it 'size'
|
36
36
|
end
|
37
37
|
end
|
data/spec/file_spec.rb
CHANGED
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'File' do
|
4
4
|
with_test_fs
|
5
|
-
|
5
|
+
|
6
6
|
before do
|
7
7
|
@path = test_fs['a/b/c']
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
describe 'existence' do
|
11
11
|
it "should check only files" do
|
12
12
|
@path.should_not exist
|
@@ -18,65 +18,65 @@ describe 'File' do
|
|
18
18
|
@path.file.should exist
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
describe 'read' do
|
23
|
-
it 'should raise error if not exist' do
|
24
|
-
-> {@path.read}.should raise_error(Vfs::Error, /not exist/)
|
25
|
-
-> {@path.read{|buff|}}.should raise_error(Vfs::Error, /not exist/)
|
23
|
+
it 'should raise error if not exist' do
|
24
|
+
-> {@path.read}.should raise_error(Vfs::Error, /not exist/)
|
25
|
+
-> {@path.read{|buff|}}.should raise_error(Vfs::Error, /not exist/)
|
26
26
|
end
|
27
|
-
|
28
|
-
it 'should not raise error in silent mode' do
|
29
|
-
@path.read(bang: false).should == ''
|
27
|
+
|
28
|
+
it 'should not raise error in silent mode' do
|
29
|
+
@path.read(bang: false).should == ''
|
30
30
|
data = ""; @path.read(bang: false){|buff| data << buff}; data.should == ''
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "reading" do
|
34
34
|
@path.write('something')
|
35
|
-
|
35
|
+
|
36
36
|
@path.read.should == 'something'
|
37
|
-
@path.read(bang: false).should == 'something'
|
38
|
-
data = ""; @path.read{|buff| data << buff}; data.should == 'something'
|
37
|
+
@path.read(bang: false).should == 'something'
|
38
|
+
data = ""; @path.read{|buff| data << buff}; data.should == 'something'
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it 'content' do
|
42
42
|
@path.write('something')
|
43
43
|
@path.content.should == 'something'
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
describe 'creation' do
|
48
48
|
it 'create' do
|
49
49
|
file = @path.file
|
50
|
-
|
50
|
+
|
51
51
|
file.should_receive(:write).with('', {})
|
52
52
|
file.create
|
53
|
-
|
53
|
+
|
54
54
|
file.should_receive(:write).with('', override: true)
|
55
55
|
file.create!
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
it 'should be chainable' do
|
59
59
|
@path.file.create.should == @path
|
60
60
|
@path.file.create!.should == @path
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
describe 'write' do
|
65
65
|
it 'should create parent dirs if not exists' do
|
66
66
|
@path.parent.should_not exist
|
67
67
|
@path.write 'something'
|
68
68
|
@path.read.should == 'something'
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
it 'should not override existing file, only if :override specified' do
|
72
72
|
@path.write 'something'
|
73
73
|
@path.should be_file
|
74
74
|
-> {@path.write 'another'}.should raise_error(Vfs::Error, /exist/)
|
75
|
-
|
75
|
+
|
76
76
|
@path.write! 'other'
|
77
77
|
@path.read.should == 'other'
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
it 'should override existing dir if :override specified' do
|
81
81
|
@path.dir.create
|
82
82
|
@path.should be_dir
|
@@ -84,7 +84,7 @@ describe 'File' do
|
|
84
84
|
@path.write! 'another'
|
85
85
|
@path.read.should == 'another'
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
it 'writing' do
|
89
89
|
@path.write 'something'
|
90
90
|
@path.read.should == 'something'
|
@@ -94,81 +94,81 @@ describe 'File' do
|
|
94
94
|
end
|
95
95
|
@path.read.should == 'another'
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
it 'append' do
|
99
99
|
file = @path.file
|
100
100
|
file.should_receive(:write).with('something', append: true)
|
101
101
|
file.append 'something'
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
it 'update' do
|
106
106
|
@path.write 'something'
|
107
|
-
@path.update do |data|
|
107
|
+
@path.update do |data|
|
108
108
|
data.should == 'something'
|
109
109
|
'another'
|
110
110
|
end
|
111
111
|
@path.read.should == 'another'
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
describe 'copying' do
|
115
|
-
before do
|
115
|
+
before do
|
116
116
|
@from = @path.file
|
117
117
|
@from.write('something')
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
it 'should not copy to itself' do
|
121
121
|
-> {@from.copy_to @from}.should raise_error(Vfs::Error, /itself/)
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def check_copy_for to
|
125
125
|
target = @from.copy_to to
|
126
126
|
target.read.should == 'something'
|
127
127
|
target.should == to
|
128
|
-
|
128
|
+
|
129
129
|
@from.write! 'another'
|
130
130
|
-> {@from.copy_to to}.should raise_error(Vfs::Error, /exist/)
|
131
131
|
target = @from.copy_to! to
|
132
132
|
target.read.should == 'another'
|
133
133
|
target.should == to
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
it 'should copy to file (and overwrite if forced)' do
|
137
137
|
check_copy_for test_fs.file('to')
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
it 'should copy to dir (and overwrite if forced)' do
|
141
141
|
check_copy_for test_fs.dir("to")
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
it 'should copy to UniversalEntry (and overwrite if forced)' do
|
145
145
|
check_copy_for test_fs.entry('to')
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
it 'should be chainable' do
|
149
149
|
to = test_fs['to']
|
150
150
|
@from.copy_to(to).should == to
|
151
151
|
@from.copy_to!(to).should == to
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
it "should autocreate parent's path if not exist (from error)" do
|
155
155
|
to = test_fs['parent_path/to']
|
156
156
|
@from.copy_to(to)
|
157
157
|
to.read.should == 'something'
|
158
158
|
end
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
describe 'moving' do
|
162
162
|
it 'move_to' do
|
163
163
|
from, to = @path.file('from'), @path.file('to')
|
164
164
|
from.should_receive(:copy_to).with(to, {})
|
165
165
|
from.should_receive(:destroy).with({})
|
166
166
|
from.move_to to
|
167
|
-
|
167
|
+
|
168
168
|
from.should_receive(:move_to).with(to, override: true)
|
169
169
|
from.move_to! to
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
it 'should be chainable' do
|
173
173
|
from, to = @path.file('from').create, @path.file('to')
|
174
174
|
from.move_to(to).should == to
|
@@ -176,7 +176,7 @@ describe 'File' do
|
|
176
176
|
from.move_to!(to).should == to
|
177
177
|
end
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
describe 'destroying' do
|
181
181
|
it "should raise error if it's trying to destroy a dir (unless force specified)" do
|
182
182
|
@path.dir.create
|
@@ -184,28 +184,28 @@ describe 'File' do
|
|
184
184
|
@path.file.destroy!
|
185
185
|
@path.entry.should_not exist
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
it "shouldn't raise if file not exist" do
|
189
189
|
@path.file.destroy
|
190
190
|
end
|
191
|
-
|
191
|
+
|
192
192
|
it 'should be chainable' do
|
193
193
|
@path.file.destroy.should == @path
|
194
194
|
@path.file.destroy!.should == @path
|
195
195
|
end
|
196
196
|
end
|
197
|
-
|
197
|
+
|
198
198
|
describe "extra stuff" do
|
199
199
|
it 'render' do
|
200
200
|
template = test_fs / 'letter.erb'
|
201
201
|
template.write "Hello dear <%= name %>"
|
202
202
|
template.render(name: 'Mary').should == "Hello dear Mary"
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
begin
|
206
206
|
require 'haml'
|
207
|
-
|
208
|
-
it 'render using other template engines' do
|
207
|
+
|
208
|
+
it 'render using other template engines' do
|
209
209
|
template = test_fs / 'letter.haml'
|
210
210
|
template.write "Hello dear \#{name}"
|
211
211
|
template.render(name: 'Mary').should =~ /Hello dear Mary/
|
@@ -213,7 +213,7 @@ describe 'File' do
|
|
213
213
|
rescue LoadError
|
214
214
|
warn "no :haml template engine, skipping rendering with haml specs"
|
215
215
|
end
|
216
|
-
|
216
|
+
|
217
217
|
it 'size'
|
218
218
|
end
|
219
219
|
end
|
data/spec/path_spec.rb
CHANGED
@@ -3,56 +3,56 @@ require 'spec_helper'
|
|
3
3
|
describe "Path" do
|
4
4
|
before(:all){Path = Vfs::Path}
|
5
5
|
after(:all){remove_constants :Path}
|
6
|
-
|
6
|
+
|
7
7
|
it 'validations' do
|
8
8
|
%w(
|
9
9
|
/
|
10
|
-
/a
|
11
|
-
/a/b/c
|
12
|
-
/a/../c
|
13
|
-
/a/...
|
14
|
-
~/a
|
10
|
+
/a
|
11
|
+
/a/b/c
|
12
|
+
/a/../c
|
13
|
+
/a/...
|
14
|
+
~/a
|
15
15
|
./a
|
16
16
|
/~a
|
17
17
|
/a~b
|
18
|
-
/a.b~
|
19
|
-
).each{|path| Path.should be_valid(path)}
|
20
|
-
|
18
|
+
/a.b~
|
19
|
+
).each{|path| Path.should be_valid(path)}
|
20
|
+
|
21
21
|
special = ['']
|
22
|
-
(%w(
|
22
|
+
(%w(
|
23
23
|
/a/~/c
|
24
|
-
/a/./c
|
24
|
+
/a/./c
|
25
25
|
/a/
|
26
26
|
~/
|
27
27
|
./
|
28
28
|
) + special).each{|path| Path.should_not be_valid(path)}
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
# it 'tmp', focus: true do
|
32
32
|
# (Path.new('.') + '..').should == './..'
|
33
33
|
# end
|
34
|
-
|
34
|
+
|
35
35
|
it 'normalize' do
|
36
36
|
special = ['/a/../..', nil]
|
37
37
|
(%w(
|
38
38
|
/a /a
|
39
39
|
~/a ~/a
|
40
40
|
./a ./a
|
41
|
-
/a/../c /c
|
41
|
+
/a/../c /c
|
42
42
|
/ /
|
43
43
|
~ ~
|
44
44
|
/a~/b /a~/b
|
45
45
|
. .
|
46
|
-
) + special).each_slice(2) do |path, normalized_path|
|
46
|
+
) + special).each_slice(2) do |path, normalized_path|
|
47
47
|
Path.normalize(path).should == normalized_path
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "+" do
|
52
52
|
special = [
|
53
53
|
'/a', '../..', nil,
|
54
|
-
'/', '..', nil,
|
55
|
-
'.', '..', './..',
|
54
|
+
'/', '..', nil,
|
55
|
+
'.', '..', './..',
|
56
56
|
]
|
57
57
|
(%w(
|
58
58
|
/ /a /a
|
@@ -64,7 +64,7 @@ describe "Path" do
|
|
64
64
|
(Path.new(base) + path).should == sum
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it 'parent' do
|
69
69
|
special = [
|
70
70
|
'/', nil,
|
@@ -72,17 +72,17 @@ describe "Path" do
|
|
72
72
|
'.', './..'
|
73
73
|
]
|
74
74
|
(%w(
|
75
|
-
/a/b/c /a/b
|
75
|
+
/a/b/c /a/b
|
76
76
|
) + special).each_slice(2) do |path, parent|
|
77
77
|
Path.new(path).parent.should == parent
|
78
78
|
end
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "should raise error if current dir outside of root" do
|
82
82
|
-> {Path.new('/a/../..')}.should raise_error(/outside.*root/)
|
83
83
|
end
|
84
|
-
|
85
|
-
it "should guess if current dir is a dir" do
|
84
|
+
|
85
|
+
it "should guess if current dir is a dir" do
|
86
86
|
[
|
87
87
|
'/a', false,
|
88
88
|
'/', true,
|
@@ -93,33 +93,33 @@ describe "Path" do
|
|
93
93
|
].each_slice 2 do |path, result|
|
94
94
|
Path.new(path).probably_dir?.should == result
|
95
95
|
end
|
96
|
-
|
97
|
-
path = Path.new('/a/b/c')
|
96
|
+
|
97
|
+
path = Path.new('/a/b/c')
|
98
98
|
[
|
99
99
|
path, false,
|
100
100
|
(path + '..'), true,
|
101
101
|
path.parent, true,
|
102
|
-
|
102
|
+
|
103
103
|
(path + '/'), true,
|
104
|
-
(path + '/a'), false,
|
104
|
+
(path + '/a'), false,
|
105
105
|
].each_slice 2 do |path, result|
|
106
106
|
path.probably_dir?.should == result
|
107
107
|
end
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
it 'name' do
|
111
111
|
%w(
|
112
112
|
/a a
|
113
113
|
/a/b/c c
|
114
114
|
/ /
|
115
|
-
~ ~
|
115
|
+
~ ~
|
116
116
|
. .
|
117
117
|
).each_slice 2 do |path, name|
|
118
118
|
Path.new(path).name.should == name
|
119
119
|
end
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
it 'to_s' do
|
123
123
|
Path.new.to_s.class.should == String
|
124
|
-
end
|
124
|
+
end
|
125
125
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,39 +5,39 @@ require 'tilt'
|
|
5
5
|
require 'vfs'
|
6
6
|
|
7
7
|
rspec do
|
8
|
-
def self.with_test_fs
|
8
|
+
def self.with_test_fs
|
9
9
|
before do
|
10
10
|
@test_fs = "/tmp/test_fs".to_dir
|
11
|
-
|
11
|
+
|
12
12
|
FileUtils.rm_r test_fs.path if File.exist? test_fs.path
|
13
13
|
FileUtils.mkdir_p test_fs.path
|
14
14
|
end
|
15
|
-
|
16
|
-
after do
|
15
|
+
|
16
|
+
after do
|
17
17
|
FileUtils.rm_r test_fs.path if File.exist? test_fs.path
|
18
18
|
@test_fs = nil
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def test_fs
|
23
23
|
@test_fs
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
# require 'fakefs/spec_helpers'
|
28
|
-
#
|
28
|
+
#
|
29
29
|
# include FakeFS::SpecHelpers
|
30
30
|
# use_fakefs self
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# #
|
31
|
+
#
|
32
|
+
#
|
33
|
+
# #
|
34
34
|
# # FakeFS fixes
|
35
|
-
# #
|
35
|
+
# #
|
36
36
|
# FakeFS::File::Stat.class_eval do
|
37
37
|
# # there's also file? method defined on File::Stat
|
38
38
|
# def file?; !directory? end
|
39
39
|
# end
|
40
|
-
#
|
40
|
+
#
|
41
41
|
# FakeFS::File.class_eval do
|
42
42
|
# class << self
|
43
43
|
# # File.delete should raise error if it's directory
|