vfs 0.3.15 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/entry_spec.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Entry' do
4
- with_test_fs
4
+ with_test_dir
5
5
 
6
6
  before do
7
- @path = test_fs['a/b/c']
7
+ @path = test_dir['a/b/c']
8
8
  end
9
9
 
10
10
  it "name" do
@@ -17,12 +17,12 @@ describe 'Entry' do
17
17
  end
18
18
 
19
19
  it 'tmp' do
20
- tmp = test_fs.tmp
20
+ tmp = test_dir.tmp
21
21
  tmp.should be_dir
22
22
  tmp.destroy
23
23
 
24
24
  tmp = nil
25
- test_fs.tmp do |path|
25
+ test_dir.tmp do |path|
26
26
  tmp = path
27
27
  tmp.should be_dir
28
28
  end
@@ -30,11 +30,11 @@ describe 'Entry' do
30
30
  end
31
31
 
32
32
  it 'should respond to local?' do
33
- test_fs.should respond_to(:local?)
33
+ test_dir.should respond_to(:local?)
34
34
  end
35
35
 
36
36
  it 'created_at, updated_at, size' do
37
- file = test_fs.file('file').write 'data'
37
+ file = test_dir.file('file').write 'data'
38
38
  file.created_at.class.should == Time
39
39
  file.updated_at.class.should == Time
40
40
  file.size.should == 4
data/spec/file_spec.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'File' do
4
- with_test_fs
4
+ with_test_dir
5
5
 
6
6
  before do
7
- @path = test_fs['a/b/c']
7
+ @path = test_dir['a/b/c']
8
8
  end
9
9
 
10
10
  describe 'existence' do
@@ -13,7 +13,7 @@ describe 'File' do
13
13
  @path.dir.create
14
14
  @path.should be_dir
15
15
  @path.file.should_not exist
16
- @path.file.create!
16
+ @path.file.create
17
17
  @path.should be_file
18
18
  @path.file.should exist
19
19
  end
@@ -38,10 +38,10 @@ describe 'File' do
38
38
  data = ""; @path.read{|buff| data << buff}; data.should == 'something'
39
39
  end
40
40
 
41
- it 'content' do
42
- @path.write('something')
43
- @path.content.should == 'something'
44
- end
41
+ # it 'content' do
42
+ # @path.write('something')
43
+ # @path.content.should == 'something'
44
+ # end
45
45
  end
46
46
 
47
47
  describe 'creation' do
@@ -50,14 +50,10 @@ describe 'File' do
50
50
 
51
51
  file.should_receive(:write).with('', {})
52
52
  file.create
53
-
54
- file.should_receive(:write).with('', override: true)
55
- file.create!
56
53
  end
57
54
 
58
55
  it 'should be chainable' do
59
56
  @path.file.create.should == @path
60
- @path.file.create!.should == @path
61
57
  end
62
58
  end
63
59
 
@@ -68,20 +64,17 @@ describe 'File' do
68
64
  @path.read.should == 'something'
69
65
  end
70
66
 
71
- it 'should not override existing file, only if :override specified' do
67
+ it 'should override existing file' do
72
68
  @path.write 'something'
73
69
  @path.should be_file
74
- -> {@path.write 'another'}.should raise_error(Vfs::Error, /exist/)
75
-
76
- @path.write! 'other'
70
+ @path.write 'other'
77
71
  @path.read.should == 'other'
78
72
  end
79
73
 
80
- it 'should override existing dir if :override specified' do
74
+ it 'should override existing dir' do
81
75
  @path.dir.create
82
76
  @path.should be_dir
83
- -> {@path.write 'another'}.should raise_error(Vfs::Error, /exist/)
84
- @path.write! 'another'
77
+ @path.write 'another'
85
78
  @path.read.should == 'another'
86
79
  end
87
80
 
@@ -89,7 +82,7 @@ describe 'File' do
89
82
  @path.write 'something'
90
83
  @path.read.should == 'something'
91
84
 
92
- @path.write! do |writer|
85
+ @path.write do |writer|
93
86
  writer.write 'another'
94
87
  end
95
88
  @path.read.should == 'another'
@@ -102,8 +95,7 @@ describe 'File' do
102
95
  end
103
96
 
104
97
  it 'should correctly display errors (from error)' do
105
- -> {test_fs['test'].write{|writer| raise 'some error'}}.should raise_error(/some error/)
106
- -> {test_fs['test'].write!{|writer| raise 'some error'}}.should raise_error(/some error/)
98
+ -> {test_dir['test'].write{|writer| raise 'some error'}}.should raise_error(/some error/)
107
99
  end
108
100
  end
109
101
 
@@ -131,33 +123,32 @@ describe 'File' do
131
123
  target.read.should == 'something'
132
124
  target.should == to
133
125
 
134
- @from.write! 'another'
135
- -> {@from.copy_to to}.should raise_error(Vfs::Error, /exist/)
136
- target = @from.copy_to! to
126
+ # overriding
127
+ @from.write 'another'
128
+ target = @from.copy_to to
137
129
  target.read.should == 'another'
138
130
  target.should == to
139
131
  end
140
132
 
141
- it 'should copy to file (and overwrite if forced)' do
142
- check_copy_for test_fs.file('to')
133
+ it 'should copy to file (and overwrite)' do
134
+ check_copy_for test_dir.file('to')
143
135
  end
144
136
 
145
- it 'should copy to dir (and overwrite if forced)' do
146
- check_copy_for test_fs.dir("to")
137
+ it 'should copy to dir (and overwrite)' do
138
+ check_copy_for test_dir.dir("to")
147
139
  end
148
140
 
149
- it 'should copy to UniversalEntry (and overwrite if forced)' do
150
- check_copy_for test_fs.entry('to')
141
+ it 'should copy to UniversalEntry (and overwrite)' do
142
+ check_copy_for test_dir.entry('to')
151
143
  end
152
144
 
153
145
  it 'should be chainable' do
154
- to = test_fs['to']
146
+ to = test_dir['to']
155
147
  @from.copy_to(to).should == to
156
- @from.copy_to!(to).should == to
157
148
  end
158
149
 
159
150
  it "should autocreate parent's path if not exist (from error)" do
160
- to = test_fs['parent_path/to']
151
+ to = test_dir['parent_path/to']
161
152
  @from.copy_to(to)
162
153
  to.read.should == 'something'
163
154
  end
@@ -166,27 +157,21 @@ describe 'File' do
166
157
  describe 'moving' do
167
158
  it 'move_to' do
168
159
  from, to = @path.file('from'), @path.file('to')
169
- from.should_receive(:copy_to).with(to, {})
170
- from.should_receive(:destroy).with({})
160
+ from.should_receive(:copy_to).with(to)
161
+ from.should_receive(:destroy).with()
171
162
  from.move_to to
172
-
173
- from.should_receive(:move_to).with(to, override: true)
174
- from.move_to! to
175
163
  end
176
164
 
177
165
  it 'should be chainable' do
178
166
  from, to = @path.file('from').create, @path.file('to')
179
167
  from.move_to(to).should == to
180
- from.create
181
- from.move_to!(to).should == to
182
168
  end
183
169
  end
184
170
 
185
171
  describe 'destroying' do
186
- it "should raise error if it's trying to destroy a dir (unless force specified)" do
172
+ it "should not raise error if it's trying to destroy a dir" do
187
173
  @path.dir.create
188
- -> {@path.file.destroy}.should raise_error(Vfs::Error, /can't destroy Dir/)
189
- @path.file.destroy!
174
+ @path.file.destroy
190
175
  @path.entry.should_not exist
191
176
  end
192
177
 
@@ -196,13 +181,12 @@ describe 'File' do
196
181
 
197
182
  it 'should be chainable' do
198
183
  @path.file.destroy.should == @path
199
- @path.file.destroy!.should == @path
200
184
  end
201
185
  end
202
186
 
203
187
  describe "extra stuff" do
204
188
  it 'render' do
205
- template = test_fs / 'letter.erb'
189
+ template = test_dir / 'letter.erb'
206
190
  template.write "Hello dear <%= name %>"
207
191
  template.render(name: 'Mary').should == "Hello dear Mary"
208
192
  end
@@ -211,7 +195,7 @@ describe 'File' do
211
195
  require 'haml'
212
196
 
213
197
  it 'render using other template engines' do
214
- template = test_fs / 'letter.haml'
198
+ template = test_dir / 'letter.haml'
215
199
  template.write "Hello dear \#{name}"
216
200
  template.render(name: 'Mary').should =~ /Hello dear Mary/
217
201
  end
data/spec/misc_spec.rb ADDED
@@ -0,0 +1,19 @@
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/spec_helper.rb CHANGED
@@ -5,22 +5,22 @@ require 'tilt'
5
5
  require 'vfs'
6
6
 
7
7
  rspec do
8
- def self.with_test_fs
8
+ def self.with_test_dir
9
9
  before do
10
- @test_fs = "/tmp/test_fs".to_dir
10
+ @test_dir = "/tmp/test_dir".to_dir
11
11
 
12
- FileUtils.rm_r test_fs.path if File.exist? test_fs.path
13
- FileUtils.mkdir_p test_fs.path
12
+ FileUtils.rm_r test_dir.path if File.exist? test_dir.path
13
+ FileUtils.mkdir_p test_dir.path
14
14
  end
15
15
 
16
16
  after do
17
- FileUtils.rm_r test_fs.path if File.exist? test_fs.path
18
- @test_fs = nil
17
+ FileUtils.rm_r test_dir.path if File.exist? test_dir.path
18
+ @test_dir = nil
19
19
  end
20
20
  end
21
21
 
22
- def test_fs
23
- @test_fs
22
+ def test_dir
23
+ @test_dir
24
24
  end
25
25
  end
26
26
 
@@ -1,24 +1,24 @@
1
- require 'vfs/storages/local'
2
- require 'vfs/storages/specification'
1
+ require 'vfs/drivers/local'
2
+ require 'vfs/drivers/specification'
3
3
 
4
- describe Vfs::Storages::Local do
4
+ describe Vfs::Drivers::Local do
5
5
  with_tmp_spec_dir
6
6
 
7
7
  before do
8
- @storage = Vfs::Storages::Local.new spec_dir
9
- @storage.open
8
+ @driver = Vfs::Drivers::Local.new root: spec_dir
9
+ @driver.open
10
10
  end
11
11
 
12
12
  after do
13
- @storage.close
13
+ @driver.close
14
14
  end
15
15
 
16
- it_should_behave_like 'vfs storage basic'
17
- it_should_behave_like 'vfs storage attributes basic'
18
- it_should_behave_like 'vfs storage files'
19
- it_should_behave_like 'vfs storage full attributes for files'
20
- it_should_behave_like 'vfs storage dirs'
21
- it_should_behave_like 'vfs storage full attributes for dirs'
22
- it_should_behave_like 'vfs storage query'
23
- it_should_behave_like 'vfs storage tmp dir'
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
24
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'UniversalEntry' do
4
- with_test_fs
4
+ with_test_dir
5
5
 
6
6
  before do
7
- @path = test_fs['a/b/c']
7
+ @path = test_dir['a/b/c']
8
8
  end
9
9
 
10
10
  describe 'existence' do
@@ -14,7 +14,7 @@ describe 'UniversalEntry' do
14
14
  @path.should be_dir
15
15
  @path.should exist
16
16
 
17
- @path.file.create!
17
+ @path.file.create
18
18
  @path.should be_file
19
19
  @path.should exist
20
20
  end
@@ -24,17 +24,13 @@ describe 'UniversalEntry' do
24
24
  it "should destroy both files and dirs" do
25
25
  @path.dir.create
26
26
  @path.should be_dir
27
- @path.destroy
27
+ @path.entry.destroy
28
28
  @path.should_not exist
29
29
 
30
30
  @path.file.create
31
31
  @path.should be_file
32
- @path.destroy
32
+ @path.entry.destroy
33
33
  @path.should_not exist
34
-
35
- @path.file.create
36
- @path.destroy!
37
- @path.file.should_not exist
38
34
  end
39
35
 
40
36
  it "shouldn't raise if file not exist" do
@@ -42,6 +38,32 @@ describe 'UniversalEntry' do
42
38
  end
43
39
  end
44
40
 
45
- describe 'copy_to'
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
+
46
68
  describe 'move_to'
47
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.15
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-25 00:00:00.000000000Z
12
+ date: 2011-09-08 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -19,23 +19,23 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - Rakefile
21
21
  - readme.md
22
+ - lib/vfs/drivers/local.rb
23
+ - lib/vfs/drivers/specification.rb
22
24
  - lib/vfs/entries/dir.rb
23
25
  - lib/vfs/entries/entry.rb
24
26
  - lib/vfs/entries/file.rb
25
27
  - lib/vfs/entries/universal_entry.rb
26
28
  - lib/vfs/entry_proxy.rb
27
29
  - lib/vfs/error.rb
28
- - lib/vfs/integration/string.rb
30
+ - lib/vfs/integration.rb
29
31
  - lib/vfs/path.rb
30
- - lib/vfs/storages/local.rb
31
- - lib/vfs/storages/specification.rb
32
- - lib/vfs/support.rb
33
32
  - lib/vfs/vfs.rb
34
33
  - lib/vfs.rb
35
34
  - spec/container_spec.rb
36
35
  - spec/dir_spec.rb
37
36
  - spec/entry_spec.rb
38
37
  - spec/file_spec.rb
38
+ - spec/misc_spec.rb
39
39
  - spec/path_spec.rb
40
40
  - spec/spec_helper.rb
41
41
  - spec/storages/local_spec/emptygit
@@ -1,20 +0,0 @@
1
- class String
2
- def to_entry_on storage = nil
3
- path = self
4
- storage ||= Vfs.default_storage
5
-
6
- path = "./#{path}" unless path =~ /^[\/\.\~]/
7
- Vfs::Dir.new(storage, path)
8
- end
9
- alias_method :to_entry, :to_entry_on
10
-
11
- def to_file_on storage = nil
12
- to_entry_on(storage).file
13
- end
14
- alias_method :to_file, :to_file_on
15
-
16
- def to_dir_on storage = nil
17
- to_entry_on(storage).dir
18
- end
19
- alias_method :to_dir, :to_dir_on
20
- end