vfs 0.4.8 → 0.5.0

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/spec/file_spec.rb DELETED
@@ -1,215 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'File' do
4
- with_test_dir
5
-
6
- before do
7
- @path = test_dir['a/b/c']
8
- end
9
-
10
- describe 'existence' do
11
- it "should check only files" do
12
- @path.should_not exist
13
- @path.dir.create
14
- @path.should be_dir
15
- @path.file.should_not exist
16
- @path.file.create
17
- @path.should be_file
18
- @path.file.should exist
19
- end
20
- end
21
-
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/)
26
- end
27
-
28
- it 'should not raise error in silent mode' do
29
- @path.read(bang: false).should == ''
30
- data = ""; @path.read(bang: false){|buff| data << buff}; data.should == ''
31
- end
32
-
33
- it "reading" do
34
- @path.write('something')
35
-
36
- @path.read.should == 'something'
37
- @path.read(bang: false).should == 'something'
38
- data = ""; @path.read{|buff| data << buff}; data.should == 'something'
39
- end
40
-
41
- # it 'content' do
42
- # @path.write('something')
43
- # @path.content.should == 'something'
44
- # end
45
- end
46
-
47
- describe 'creation' do
48
- it 'create' do
49
- file = @path.file
50
-
51
- file.should_receive(:write).with('', {})
52
- file.create
53
- end
54
-
55
- it 'should be chainable' do
56
- @path.file.create.should == @path
57
- end
58
- end
59
-
60
- describe 'write' do
61
- it 'should create parent dirs if not exists' do
62
- @path.parent.should_not exist
63
- @path.write 'something'
64
- @path.read.should == 'something'
65
- end
66
-
67
- it 'should write empty file' do
68
- @path.write
69
- @path.read.should == ''
70
- end
71
-
72
- it 'should override existing file' do
73
- @path.write 'something'
74
- @path.should be_file
75
- @path.write 'other'
76
- @path.read.should == 'other'
77
- end
78
-
79
- it 'should override existing dir' do
80
- @path.dir.create
81
- @path.should be_dir
82
- @path.write 'another'
83
- @path.read.should == 'another'
84
- end
85
-
86
- it 'writing' do
87
- @path.write 'something'
88
- @path.read.should == 'something'
89
-
90
- @path.write do |writer|
91
- writer.write 'another'
92
- end
93
- @path.read.should == 'another'
94
- end
95
-
96
- it 'append' do
97
- file = @path.file
98
- file.should_receive(:write).with('something', append: true)
99
- file.append 'something'
100
- end
101
-
102
- it 'should correctly display errors (from error)' do
103
- -> {test_dir['test'].write{|writer| raise 'some error'}}.should raise_error(/some error/)
104
- end
105
- end
106
-
107
- it 'update' do
108
- @path.write 'something'
109
- @path.update do |data|
110
- data.should == 'something'
111
- 'another'
112
- end
113
- @path.read.should == 'another'
114
- end
115
-
116
- describe 'copying' do
117
- before do
118
- @from = @path.file
119
- @from.write('something')
120
- end
121
-
122
- it 'should not copy to itself' do
123
- -> {@from.copy_to @from}.should raise_error(Vfs::Error, /itself/)
124
- end
125
-
126
- def check_copy_for to
127
- target = @from.copy_to to
128
- target.read.should == 'something'
129
- target.should == to
130
-
131
- # overriding
132
- @from.write 'another'
133
- target = @from.copy_to to
134
- target.read.should == 'another'
135
- target.should == to
136
- end
137
-
138
- it 'should copy to file (and overwrite)' do
139
- check_copy_for test_dir.file('to')
140
- end
141
-
142
- it 'should copy to dir (and overwrite)' do
143
- check_copy_for test_dir.dir("to")
144
- end
145
-
146
- it 'should copy to UniversalEntry (and overwrite)' do
147
- check_copy_for test_dir.entry('to')
148
- end
149
-
150
- it 'should be chainable' do
151
- to = test_dir['to']
152
- @from.copy_to(to).should == to
153
- end
154
-
155
- it "should autocreate parent's path if not exist (from error)" do
156
- to = test_dir['parent_path/to']
157
- @from.copy_to(to)
158
- to.read.should == 'something'
159
- end
160
- end
161
-
162
- describe 'moving' do
163
- it 'move_to' do
164
- from, to = @path.file('from'), @path.file('to')
165
- from.should_receive(:copy_to).with(to)
166
- from.should_receive(:destroy).with()
167
- from.move_to to
168
- end
169
-
170
- it 'should be chainable' do
171
- from, to = @path.file('from').create, @path.file('to')
172
- from.move_to(to).should == to
173
- end
174
- end
175
-
176
- describe 'destroying' do
177
- it "should not raise error if it's trying to destroy a dir" do
178
- @path.dir.create
179
- @path.file.destroy
180
- @path.entry.should_not exist
181
- end
182
-
183
- it "shouldn't raise if file not exist" do
184
- @path.file.destroy
185
- end
186
-
187
- it 'should be chainable' do
188
- @path.file.destroy.should == @path
189
- end
190
- end
191
-
192
- describe "extra stuff" do
193
- it 'render' do
194
- template = test_dir / 'letter.erb'
195
- template.write "Hello dear <%= name %>"
196
- template.render(name: 'Mary').should == "Hello dear Mary"
197
- end
198
-
199
- begin
200
- require 'haml'
201
-
202
- it 'render using other template engines' do
203
- template = test_dir / 'letter.haml'
204
- template.write "Hello dear \#{name}"
205
- template.render(name: 'Mary').should =~ /Hello dear Mary/
206
- end
207
- rescue LoadError
208
- warn "no :haml template engine, skipping rendering with haml specs"
209
- end
210
-
211
- it 'size' do
212
- @path.file.write('data').size.should == 4
213
- end
214
- end
215
- end
data/spec/misc_spec.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Miscellaneous' do
4
- with_test_dir
5
-
6
- it "File should respond to :to_file, :to_entry" do
7
- path = "#{test_dir.path}/file"
8
- File.open(path, 'w'){|f| f.write 'something'}
9
-
10
- file = nil
11
- begin
12
- file = File.open path
13
- file.to_file.path.should == file.path
14
- file.to_entry.path.should == file.path
15
- ensure
16
- file.close
17
- end
18
- end
19
- end
data/spec/path_spec.rb DELETED
@@ -1,127 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Path" do
4
- before(:all){Path = Vfs::Path}
5
- after(:all){remove_constants :Path}
6
-
7
- it 'validations' do
8
- %w(
9
- /
10
- /a
11
- /a/b/c
12
- /a/../c
13
- /a/...
14
- ~/a
15
- ./a
16
- /~a
17
- /a~b
18
- /a.b~
19
- ).each{|path| Path.should be_valid(path)}
20
-
21
- special = ['']
22
- (%w(
23
- /a/~/c
24
- /a/./c
25
- /a/
26
- ~/
27
- ./
28
- ) + special).each{|path| Path.should_not be_valid(path)}
29
- end
30
-
31
- # it 'tmp' do
32
- # (Path.new('.') + '..').should == './..'
33
- # end
34
-
35
- it 'normalize' do
36
- special = ['/a/../..', nil]
37
- (%w(
38
- /a /a
39
- ~/a ~/a
40
- ./a ./a
41
- /a/../c /c
42
- / /
43
- ~ ~
44
- /a~/b /a~/b
45
- . .
46
- ) + special).each_slice(2) do |path, normalized_path|
47
- Path.normalize(path).should == normalized_path
48
- end
49
- end
50
-
51
- it "+" do
52
- special = [
53
- '/a', '../..', nil,
54
- '/', '..', nil,
55
- '.', '..', './..',
56
- ]
57
- (%w(
58
- / /a /a
59
- / ~/a ~/a
60
- / ./a ./a
61
- /a b/c /a/b/c
62
- /a/b/c ../d /a/b/d
63
- ) + special).each_slice(3) do |base, path, sum|
64
- (Path.new(base) + path).should == sum
65
- end
66
- end
67
-
68
- it 'parent' do
69
- special = [
70
- '/', nil,
71
- '~', nil,
72
- '.', './..'
73
- ]
74
- (%w(
75
- /a/b/c /a/b
76
- ./a/b/c ./a/b
77
- ~/a/b/c ~/a/b
78
- ) + special).each_slice(2) do |path, parent|
79
- Path.new(path).parent.should == parent
80
- end
81
- end
82
-
83
- it "should raise error if current dir outside of root" do
84
- -> {Path.new('/a/../..')}.should raise_error(/outside.*root/)
85
- end
86
-
87
- it "should guess if current dir is a dir" do
88
- [
89
- '/a', false,
90
- '/', true,
91
- '~', true,
92
- '.', true,
93
- '/a/..', true,
94
- '/a/../b', false,
95
- ].each_slice 2 do |path, result|
96
- Path.new(path).probably_dir?.should == result
97
- end
98
-
99
- path = Path.new('/a/b/c')
100
- [
101
- path, false,
102
- (path + '..'), true,
103
- path.parent, true,
104
-
105
- (path + '/'), true,
106
- (path + '/a'), false,
107
- ].each_slice 2 do |path, result|
108
- path.probably_dir?.should == result
109
- end
110
- end
111
-
112
- it 'name' do
113
- %w(
114
- /a a
115
- /a/b/c c
116
- / /
117
- ~ ~
118
- . .
119
- ).each_slice 2 do |path, name|
120
- Path.new(path).name.should == name
121
- end
122
- end
123
-
124
- it 'to_s' do
125
- Path.new.to_s.class.should == String
126
- end
127
- end
data/spec/spec_helper.rb DELETED
@@ -1,50 +0,0 @@
1
- require 'rspec_ext'
2
- require 'ruby_ext'
3
-
4
- require 'tilt'
5
- require 'vfs'
6
-
7
- rspec do
8
- def self.with_test_dir
9
- before do
10
- @test_dir = "/tmp/test_dir".to_dir
11
-
12
- FileUtils.rm_r test_dir.path if File.exist? test_dir.path
13
- FileUtils.mkdir_p test_dir.path
14
- end
15
-
16
- after do
17
- FileUtils.rm_r test_dir.path if File.exist? test_dir.path
18
- @test_dir = nil
19
- end
20
- end
21
-
22
- def test_dir
23
- @test_dir
24
- end
25
- end
26
-
27
- # require 'fakefs/spec_helpers'
28
- #
29
- # include FakeFS::SpecHelpers
30
- # use_fakefs self
31
- #
32
- #
33
- # #
34
- # # FakeFS fixes
35
- # #
36
- # FakeFS::File::Stat.class_eval do
37
- # # there's also file? method defined on File::Stat
38
- # def file?; !directory? end
39
- # end
40
- #
41
- # FakeFS::File.class_eval do
42
- # class << self
43
- # # File.delete should raise error if it's directory
44
- # alias_method :delete_without_bang, :delete
45
- # def delete path
46
- # raise Errno::EPERM, "Operation not permitted - #{path}" if directory?(path)
47
- # delete_without_bang path
48
- # end
49
- # end
50
- # end
@@ -1,24 +0,0 @@
1
- require 'vfs/drivers/local'
2
- require 'vfs/drivers/specification'
3
-
4
- describe Vfs::Drivers::Local do
5
- with_tmp_spec_dir
6
-
7
- before do
8
- @driver = Vfs::Drivers::Local.new root: spec_dir
9
- @driver.open
10
- end
11
-
12
- after do
13
- @driver.close
14
- end
15
-
16
- it_should_behave_like 'vfs driver basic'
17
- it_should_behave_like 'vfs driver attributes basic'
18
- it_should_behave_like 'vfs driver files'
19
- it_should_behave_like 'vfs driver full attributes for files'
20
- it_should_behave_like 'vfs driver dirs'
21
- it_should_behave_like 'vfs driver full attributes for dirs'
22
- it_should_behave_like 'vfs driver query'
23
- it_should_behave_like 'vfs driver tmp dir'
24
- end
File without changes
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'UniversalEntry' do
4
- with_test_dir
5
-
6
- before do
7
- @path = test_dir['a/b/c']
8
- end
9
-
10
- describe 'existence' do
11
- it "should check both files and dirs" do
12
- @path.should_not exist
13
- @path.dir.create
14
- @path.should be_dir
15
- @path.should exist
16
-
17
- @path.file.create
18
- @path.should be_file
19
- @path.should exist
20
- end
21
- end
22
-
23
- describe 'destroying' do
24
- it "should destroy both files and dirs" do
25
- @path.dir.create
26
- @path.should be_dir
27
- @path.entry.destroy
28
- @path.should_not exist
29
-
30
- @path.file.create
31
- @path.should be_file
32
- @path.entry.destroy
33
- @path.should_not exist
34
- end
35
-
36
- it "shouldn't raise if file not exist" do
37
- @path.destroy
38
- end
39
- end
40
-
41
- describe 'copy_to' do
42
- before do
43
- @from = @path.dir
44
- @from.create
45
- @from.file('file').write 'something'
46
- @from.dir('dir').create.tap do |dir|
47
- dir.file('file2').write 'something2'
48
- end
49
-
50
- @to = test_dir['to']
51
- end
52
-
53
- it "shoud copy dir" do
54
- @from.entry.copy_to @to
55
- @to['dir/file2'].file?.should be_true
56
- end
57
-
58
- it "should copy file" do
59
- @from['file'].entry.copy_to @to
60
- @to.file.should be_true
61
- end
62
-
63
- it "should raise if entry not exist" do
64
- -> {@from['non existing'].entry.copy_to @to}.should raise_error(/not exist/)
65
- end
66
- end
67
-
68
- describe 'move_to'
69
- end