vfs 0.3.14 → 0.3.15

Sign up to get free protection for your applications and to get access to all the features.
data/lib/vfs.rb CHANGED
@@ -4,7 +4,6 @@
4
4
  path
5
5
  error
6
6
 
7
- entries/entry/special_attributes
8
7
  entries/entry
9
8
  entries/file
10
9
  entries/dir
@@ -25,7 +25,7 @@ module Vfs
25
25
  # CRUD
26
26
  #
27
27
  def create options = {}
28
- storage.open_fs do |fs|
28
+ storage.open do |fs|
29
29
  try = 0
30
30
  begin
31
31
  try += 1
@@ -33,13 +33,13 @@ module Vfs
33
33
  rescue StandardError => error
34
34
  entry = self.entry
35
35
  attrs = entry.get
36
- if attrs[:file] #entry.exist?
36
+ if attrs and attrs[:file] #entry.exist?
37
37
  if options[:override]
38
38
  entry.destroy
39
39
  else
40
40
  raise Error, "entry #{self} already exist!"
41
41
  end
42
- elsif attrs[:dir]
42
+ elsif attrs and attrs[:dir]
43
43
  # dir already exist, no need to recreate it
44
44
  return self
45
45
  else
@@ -63,18 +63,18 @@ module Vfs
63
63
  end
64
64
 
65
65
  def destroy options = {}
66
- storage.open_fs do |fs|
66
+ storage.open do |fs|
67
67
  begin
68
68
  fs.delete_dir path
69
69
  rescue StandardError => e
70
70
  attrs = get
71
- if attrs[:file]
71
+ if attrs and attrs[:file]
72
72
  if options[:force]
73
73
  file.destroy
74
74
  else
75
75
  raise Error, "can't destroy File #{dir} (You are trying to destroy it as if it's a Dir)"
76
76
  end
77
- elsif attrs[:dir]
77
+ elsif attrs and attrs[:dir]
78
78
  # unknown internal error
79
79
  raise e
80
80
  else
@@ -99,7 +99,7 @@ module Vfs
99
99
  query = args.first
100
100
  options[:bang] = true unless options.include? :bang
101
101
 
102
- storage.open_fs do |fs|
102
+ storage.open do |fs|
103
103
  begin
104
104
  list = []
105
105
  # query option is optional and supported only for some storages (local fs for example)
@@ -117,9 +117,9 @@ module Vfs
117
117
  block ? nil : list
118
118
  rescue StandardError => error
119
119
  attrs = get
120
- if attrs[:file]
120
+ if attrs and attrs[:file]
121
121
  raise Error, "can't query entries on File ('#{self}')!"
122
- elsif attrs[:dir]
122
+ elsif attrs and attrs[:dir]
123
123
  # unknown error
124
124
  raise error
125
125
  else
@@ -229,9 +229,9 @@ module Vfs
229
229
  # unknown_errors = 0
230
230
  #
231
231
  # attrs = get
232
- # if attrs[:file]
232
+ # if attrs and attrs[:file]
233
233
  # raise Error, "can't copy File as a Dir ('#{self}')!"
234
- # elsif attrs[:dir]
234
+ # elsif attrs and attrs[:dir]
235
235
  # # some unknown error (but it also maybe caused by to be fixed error in 'to')
236
236
  # unknown_errors += 1
237
237
  # else
@@ -240,13 +240,13 @@ module Vfs
240
240
  # end
241
241
  #
242
242
  # attrs = to.get
243
- # if attrs[:file]
243
+ # if attrs and attrs[:file]
244
244
  # if options[:override]
245
245
  # to.destroy
246
246
  # else
247
247
  # raise Vfs::Error, "entry #{to} already exist!"
248
248
  # end
249
- # elsif attrs[:dir]
249
+ # elsif attrs and attrs[:dir]
250
250
  # unknown_errors += 1
251
251
  # # if options[:override]
252
252
  # # to.destroy
@@ -65,18 +65,19 @@ module Vfs
65
65
  # Attributes
66
66
  #
67
67
  def get attr_name = nil
68
- attrs = storage.open_fs{|fs| fs.attributes(path)}
69
- attr_name ? attrs[attr_name] : attrs
68
+ attrs = storage.open{|fs| fs.attributes(path)}
69
+ (attr_name and attrs) ? attrs[attr_name] : attrs
70
70
  end
71
71
 
72
72
  def set options
73
+ # TODO2 set attributes
73
74
  not_implemented
74
75
  end
75
76
 
76
77
  def dir?; !!get(:dir) end
77
78
  def file?; !!get(:file) end
78
-
79
- include SpecialAttributes
79
+ def created_at; get :created_at end
80
+ def updated_at; get :updated_at end
80
81
 
81
82
 
82
83
  #
@@ -87,7 +88,7 @@ module Vfs
87
88
  end
88
89
 
89
90
  def tmp &block
90
- storage.open_fs do |fs|
91
+ storage.open do |fs|
91
92
  if block
92
93
  fs.tmp do |path|
93
94
  block.call Dir.new(storage, path)
@@ -11,7 +11,7 @@ module Vfs
11
11
  #
12
12
  def read options = {}, &block
13
13
  options[:bang] = true unless options.include? :bang
14
- storage.open_fs do |fs|
14
+ storage.open do |fs|
15
15
  begin
16
16
  if block
17
17
  fs.read_file path, &block
@@ -23,10 +23,10 @@ module Vfs
23
23
  rescue StandardError => e
24
24
  raise Vfs::Error, "can't read Dir #{self}!" if dir.exist?
25
25
  attrs = get
26
- if attrs[:file]
26
+ if attrs and attrs[:file]
27
27
  # unknown internal error
28
28
  raise e
29
- elsif attrs[:dir]
29
+ elsif attrs and attrs[:dir]
30
30
  raise Error, "You are trying to read Dir '#{self}' as if it's a File!"
31
31
  else
32
32
  if options[:bang]
@@ -61,7 +61,7 @@ module Vfs
61
61
  end
62
62
  raise "can't do :override and :append at the same time!" if options[:override] and options[:append]
63
63
 
64
- storage.open_fs do |fs|
64
+ storage.open do |fs|
65
65
  # TODO2 Performance lost, extra call to check file existence
66
66
  # We need to check if the file exist before writing to it, otherwise it's
67
67
  # impossible to distinguish if the StandardError caused by the 'already exist' error or
@@ -116,19 +116,19 @@ module Vfs
116
116
  end
117
117
 
118
118
  def destroy options = {}
119
- storage.open_fs do |fs|
119
+ storage.open do |fs|
120
120
  begin
121
121
  fs.delete_file path
122
122
  self
123
123
  rescue StandardError => e
124
124
  attrs = get
125
- if attrs[:dir]
125
+ if attrs and attrs[:dir]
126
126
  if options[:force]
127
127
  dir.destroy
128
128
  else
129
129
  raise Error, "can't destroy Dir #{dir} (you are trying to destroy it as if it's a File)"
130
130
  end
131
- elsif attrs[:file]
131
+ elsif attrs and attrs[:file]
132
132
  # unknown internal error
133
133
  raise e
134
134
  else
@@ -194,9 +194,7 @@ module Vfs
194
194
  template.render *args
195
195
  end
196
196
 
197
- def size
198
- get :size
199
- end
197
+ def size; get :size end
200
198
 
201
199
  def basename
202
200
  ::File.basename(name, File.extname(name))
@@ -4,8 +4,7 @@ module Vfs
4
4
  # Attributes
5
5
  #
6
6
  def exist?
7
- attrs = get
8
- !!(attrs[:dir] or attrs[:file])
7
+ !!get
9
8
  end
10
9
 
11
10
 
@@ -13,10 +12,10 @@ module Vfs
13
12
  # CRUD
14
13
  #
15
14
  def destroy options = {}
16
- storage.open_fs do |fs|
15
+ storage.open do |fs|
17
16
  attrs = get
18
- fs.delete_dir path if attrs[:dir]
19
- fs.delete_file path if attrs[:file]
17
+ fs.delete_dir path if attrs and attrs[:dir]
18
+ fs.delete_file path if attrs and attrs[:file]
20
19
  end
21
20
  self
22
21
  end
@@ -18,6 +18,13 @@ module Vfs
18
18
  protected
19
19
  attr_writer :_target
20
20
 
21
+ def respond_to? m
22
+ super or
23
+ ::Vfs::UniversalEntry.method_defined?(m) or
24
+ ::Vfs::Dir.method_defined?(m) or
25
+ ::Vfs::File.method_defined?(m)
26
+ end
27
+
21
28
  def method_missing m, *a, &b
22
29
  unless _target.respond_to? m
23
30
  if ::Vfs::UniversalEntry.method_defined? m
@@ -21,22 +21,25 @@ module Vfs
21
21
  # Attributes
22
22
  #
23
23
  def attributes path
24
+ path = with_root path
25
+
24
26
  stat = ::File.stat path
25
27
  attrs = {}
26
- attrs[:file] = stat.file?
27
- attrs[:dir] = stat.directory?
28
+ attrs[:file] = !!stat.file?
29
+ attrs[:dir] = !!stat.directory?
28
30
 
29
31
  # attributes special for file system
30
32
  attrs[:created_at] = stat.ctime
31
33
  attrs[:updated_at] = stat.mtime
32
- attrs[:size] = stat.size if stat.file?
34
+ attrs[:size] = stat.size if attrs[:file]
33
35
  attrs
34
36
  rescue Errno::ENOENT
35
- {}
37
+ nil
36
38
  end
37
39
 
38
40
  def set_attributes path, attrs
39
- raise 'not supported'
41
+ # TODO2 set attributes
42
+ not_implemented
40
43
  end
41
44
 
42
45
 
@@ -44,6 +47,7 @@ module Vfs
44
47
  # File
45
48
  #
46
49
  def read_file path, &block
50
+ path = with_root path
47
51
  ::File.open path, 'r' do |is|
48
52
  while buff = is.gets(self.buffer || DEFAULT_BUFFER)
49
53
  block.call buff
@@ -51,9 +55,11 @@ module Vfs
51
55
  end
52
56
  end
53
57
 
54
- def write_file path, append, &block
58
+ def write_file original_path, append, &block
59
+ path = with_root original_path
60
+
55
61
  # TODO2 Performance lost, extra call to check file existence
56
- raise "can't write, entry #{path} already exist!" if !append and ::File.exist?(path)
62
+ raise "can't write, entry #{original_path} already exist!" if !append and ::File.exist?(path)
57
63
 
58
64
  option = append ? 'a' : 'w'
59
65
  ::File.open path, option do |out|
@@ -62,6 +68,7 @@ module Vfs
62
68
  end
63
69
 
64
70
  def delete_file path
71
+ path = with_root path
65
72
  ::File.delete path
66
73
  end
67
74
 
@@ -74,21 +81,27 @@ module Vfs
74
81
  # Dir
75
82
  #
76
83
  def create_dir path
84
+ path = with_root path
77
85
  ::Dir.mkdir path
78
86
  end
79
87
 
80
- def delete_dir path
88
+ def delete_dir original_path
89
+ path = with_root original_path
90
+
81
91
  # TODO2 Performance lost, extra call to check file existence
82
- raise "can't delete file (#{path})!" if ::File.file?(path)
92
+ raise "can't delete file (#{original_path})!" if ::File.file?(path)
83
93
 
84
- FileUtils.rm_r path
94
+ ::FileUtils.rm_r path
85
95
  end
86
96
 
87
97
  def each_entry path, query, &block
98
+ path = with_root path
99
+
88
100
  if query
89
101
  path_with_trailing_slash = path == '/' ? path : "#{path}/"
90
102
  ::Dir["#{path_with_trailing_slash}#{query}"].each do |absolute_path|
91
103
  relative_path = absolute_path.sub path_with_trailing_slash, ''
104
+ # TODO2 Performance loss
92
105
  if ::File.directory? absolute_path
93
106
  block.call relative_path, :dir
94
107
  else
@@ -128,28 +141,43 @@ module Vfs
128
141
  def local?; true end
129
142
 
130
143
  def tmp &block
131
- tmp_dir = "#{::Dir.tmpdir}/#{rand(10**6)}"
144
+ path = "/tmp/#{rand(10**6)}"
145
+ # tmp_dir = "#{::Dir.tmpdir}/#{rand(10**6)}"
132
146
  if block
133
147
  begin
134
- create_dir tmp_dir
135
- block.call tmp_dir
148
+ ::FileUtils.mkdir_p with_root(path)
149
+ block.call path
136
150
  ensure
137
- delete_dir tmp_dir
151
+ ::FileUtils.rm_r with_root(path) if ::File.exist? with_root(path)
138
152
  end
139
153
  else
140
- create_dir tmp_dir
141
- tmp_dir
154
+ ::FileUtils.mkdir_p with_root(path)
155
+ path
142
156
  end
143
157
  end
144
158
 
145
159
  def to_s; '' end
160
+
161
+ protected
162
+ def root
163
+ @root || raise('root not defined!')
164
+ end
165
+
166
+ def with_root path
167
+ path == '/' ? root : root + path
168
+ end
146
169
  end
147
170
 
148
171
  include LocalVfsHelper
149
172
 
150
- def open_fs &block
151
- block.call self
173
+ def initialize root = ''
174
+ @root = root
175
+ end
176
+
177
+ def open &block
178
+ block.call self if block
152
179
  end
180
+ def close; end
153
181
  end
154
182
  end
155
183
  end
@@ -1,129 +1,161 @@
1
- # use '$ gem install ruby_ext' to install.
2
1
  require 'rspec_ext'
3
2
  require 'ruby_ext'
4
3
 
5
- shared_examples_for 'vfs storage' do
6
- before do
7
- @storage.open_fs do |fs|
8
- @tmp_dir = fs.tmp
9
- end
4
+ shared_examples_for 'vfs storage basic' do
5
+ it 'should respond to :local?' do
6
+ @storage.should respond_to(:local?)
10
7
  end
11
8
 
12
- after do
13
- @storage.open_fs do |fs|
14
- attrs = fs.attributes(@tmp_dir)
15
- fs.delete_dir @tmp_dir if attrs && attrs[:dir]
16
- end
9
+ it "should provide open method" do
10
+ @storage.open
11
+ @storage.open{'result'}.should == 'result'
17
12
  end
13
+ end
18
14
 
19
- it 'should respond to :local?' do
20
- @storage.open_fs{|fs| fs.should respond_to(:local?)}
15
+ shared_examples_for 'vfs storage attributes basic' do
16
+ it 'should have root dir' do
17
+ attrs = @storage.attributes('/')
18
+ attrs[:dir].should be_true
19
+ attrs[:file].should be_false
21
20
  end
22
21
 
23
- it 'should respond to :host'
24
-
25
- it 'should have root dir' do
26
- @storage.open_fs do |fs|
27
- fs.attributes('/').subset(:file, :dir).should == {file: false, dir: true}
28
- end
22
+ it "attributes should return nil if there's no entry" do
23
+ @storage.attributes('/non_existing_entry').should be_nil
29
24
  end
25
+ end
30
26
 
31
- describe "files" do
32
- before do
33
- @remote_file = "#{@tmp_dir}/remote_file"
34
- end
27
+ shared_examples_for 'vfs storage files' do
28
+ it "file attributes" do
29
+ @storage.attributes('/file').should be_nil
35
30
 
36
- it "file attributes" do
37
- @storage.open_fs do |fs|
38
- fs.attributes(@remote_file).should == {}
39
- fs.write_file(@remote_file, false){|w| w.write 'something'}
40
- attrs = fs.attributes(@remote_file)
41
- fs.attributes(@remote_file).subset(:file, :dir).should == {file: true, dir: false}
42
- end
43
- end
31
+ @storage.write_file('/file', false){|w| w.write 'something'}
32
+ attrs = @storage.attributes('/file')
33
+ attrs[:file].should be_true
34
+ attrs[:dir].should be_false
35
+ end
44
36
 
45
- it "read, write & append" do
46
- @storage.open_fs do |fs|
47
- fs.write_file(@remote_file, false){|w| w.write 'something'}
48
- fs.attributes(@remote_file)[:file].should be_true
49
-
50
- data = ""
51
- fs.read_file(@remote_file){|buff| data << buff}
52
- data.should == 'something'
53
-
54
- # append
55
- fs.write_file(@remote_file, true){|w| w.write ' another'}
56
- data = ""
57
- fs.read_file(@remote_file){|buff| data << buff}
58
- data.should == 'something another'
59
- end
60
- end
37
+ it "read, write, append" do
38
+ # write
39
+ @storage.write_file('/file', false){|w| w.write 'something'}
40
+ @storage.attributes('/file')[:file].should == true
41
+
42
+ # read
43
+ data = ""
44
+ @storage.read_file('/file'){|buff| data << buff}
45
+ data.should == 'something'
46
+
47
+ # append
48
+ @storage.write_file('/file', true){|w| w.write ' another'}
49
+ data = ""
50
+ @storage.read_file('/file'){|buff| data << buff}
51
+ data.should == 'something another'
52
+ end
61
53
 
62
- it "delete_file" do
63
- @storage.open_fs do |fs|
64
- fs.write_file(@remote_file, false){|w| w.write 'something'}
65
- fs.attributes(@remote_file)[:file].should be_true
66
- fs.delete_file(@remote_file)
67
- fs.attributes(@remote_file).should == {}
68
- end
69
- end
54
+ it "delete_file" do
55
+ @storage.write_file('/file', false){|w| w.write 'something'}
56
+ @storage.attributes('/file')[:file].should be_true
57
+ @storage.delete_file('/file')
58
+ @storage.attributes('/file').should be_nil
59
+ end
60
+ end
61
+
62
+ shared_examples_for 'vfs storage full attributes for files' do
63
+ it "attributes for files" do
64
+ @storage.write_file('/file', false){|w| w.write 'something'}
65
+ attrs = @storage.attributes('/file')
66
+ attrs[:file].should be_true
67
+ attrs[:dir].should be_false
68
+ attrs[:created_at].class.should == Time
69
+ attrs[:updated_at].class.should == Time
70
+ attrs[:size].should == 9
70
71
  end
72
+ end
71
73
 
72
- describe 'directories' do
73
- # before do
74
- # @from_local, @remote_path, @to_local = "#{@local_dir}/dir", "#{@tmp_dir}/upload", "#{@local_dir}/download"
75
- # end
74
+ shared_examples_for 'vfs storage dirs' do
75
+ it "directory crud" do
76
+ @storage.attributes('/dir').should be_nil
76
77
 
77
- before do
78
- @remote_dir = "#{@tmp_dir}/some_dir"
79
- end
78
+ @storage.create_dir('/dir')
79
+ attrs = @storage.attributes('/dir')
80
+ attrs[:file].should be_false
81
+ attrs[:dir].should be_true
80
82
 
81
- it "directory_exist?, create_dir, delete_dir" do
82
- @storage.open_fs do |fs|
83
- fs.attributes(@remote_dir).should == {}
84
- fs.create_dir(@remote_dir)
85
- fs.attributes(@remote_dir).subset(:file, :dir).should == {file: false, dir: true}
86
- fs.delete_dir(@remote_dir)
87
- fs.attributes(@remote_dir).should == {}
88
- end
89
- end
83
+ @storage.delete_dir('/dir')
84
+ @storage.attributes('/dir').should be_nil
85
+ end
90
86
 
91
- it 'should delete not-empty directories' do
92
- @storage.open_fs do |fs|
93
- fs.create_dir(@remote_dir)
94
- fs.create_dir("#{@remote_dir}/dir")
95
- fs.write_file("#{@remote_dir}/dir/file", false){|w| w.write 'something'}
96
- fs.delete_dir(@remote_dir)
97
- fs.attributes(@remote_dir).should == {}
98
- end
99
- end
87
+ it 'should delete not-empty directories' do
88
+ @storage.create_dir('/dir')
89
+ @storage.create_dir('/dir/dir2')
90
+ @storage.write_file('/dir/dir2/file', false){|w| w.write 'something'}
91
+ @storage.attributes('/dir').should_not be_nil
100
92
 
101
- it 'each' do
102
- @storage.open_fs do |fs|
103
- list = {}
104
- fs.each_entry(@tmp_dir, nil){|path, type| list[path] = type}
105
- list.should be_empty
93
+ @storage.delete_dir('/dir')
94
+ @storage.attributes('/dir').should be_nil
95
+ end
106
96
 
107
- dir, file = "#{@tmp_dir}/dir", "#{@tmp_dir}/file"
108
- fs.create_dir(dir)
109
- fs.write_file(file, false){|w| w.write 'something'}
97
+ it 'each' do
98
+ -> {@storage.each_entry('/not_existing_dir', nil){|path, type| list[path] = type}}.should raise_error
110
99
 
111
- list = {}
112
- fs.each_entry(@tmp_dir, nil){|path, type| list[path] = type}
113
- list.should == {'dir' => :dir, 'file' => :file}
114
- end
115
- end
100
+ @storage.create_dir '/dir'
101
+ @storage.create_dir('/dir/dir2')
102
+ @storage.write_file('/dir/file', false){|w| w.write 'something'}
103
+
104
+ list = {}
105
+ @storage.each_entry('/dir', nil){|path, type| list[path] = type}
106
+ list.should == {'dir2' => :dir, 'file' => :file}
107
+ end
116
108
 
117
- # it "upload_directory & download_directory" do
118
- # upload_path_check = "#{@remote_path}/dir2/file"
119
- # check_attributes upload_path_check, nil
120
- # fs.upload_directory(@from_local, @remote_path)
121
- # check_attributes upload_path_check, file: true, dir: false
122
- #
123
- # download_path_check = "#{@to_local}/dir2/file"
124
- # File.exist?(download_path_check).should be_false
125
- # fs.download_directory(@remote_path, @to_local)
126
- # File.exist?(download_path_check).should be_true
127
- # end
109
+ # it "upload_directory & download_directory" do
110
+ # upload_path_check = "#{@remote_path}/dir2/file"
111
+ # check_attributes upload_path_check, nil
112
+ # @storage.upload_directory(@from_local, @remote_path)
113
+ # check_attributes upload_path_check, file: true, dir: false
114
+ #
115
+ # download_path_check = "#{@to_local}/dir2/file"
116
+ # File.exist?(download_path_check).should be_false
117
+ # @storage.download_directory(@remote_path, @to_local)
118
+ # File.exist?(download_path_check).should be_true
119
+ # end
120
+ end
121
+
122
+ shared_examples_for 'vfs storage query' do
123
+ it 'each with query' do
124
+ @storage.create_dir '/dir'
125
+ @storage.create_dir('/dir/dir_a')
126
+ @storage.create_dir('/dir/dir_b')
127
+ @storage.write_file('/dir/file_a', false){|w| w.write 'something'}
128
+
129
+ list = {}
130
+ @storage.each_entry('/dir', '*_a'){|path, type| list[path] = type}
131
+ list.should == {'dir_a' => :dir, 'file_a' => :file}
132
+ end
133
+ end
134
+
135
+ shared_examples_for 'vfs storage full attributes for dirs' do
136
+ it "attributes for dirs" do
137
+ @storage.create_dir('/dir')
138
+ attrs = @storage.attributes('/dir')
139
+ attrs[:file].should be_false
140
+ attrs[:dir].should be_true
141
+ attrs[:created_at].class.should == Time
142
+ attrs[:updated_at].class.should == Time
143
+ attrs.should_not include(:size)
144
+ end
145
+ end
146
+
147
+ shared_examples_for 'vfs storage tmp dir' do
148
+ it "tmp dir" do
149
+ dir = @storage.tmp
150
+ @storage.attributes(dir).should_not be_nil
151
+ @storage.delete_dir dir
152
+ @storage.attributes(dir).should be_nil
153
+
154
+ dir = nil
155
+ @storage.tmp do |tmp_dir|
156
+ dir = tmp_dir
157
+ @storage.attributes(dir).should_not be_nil
158
+ end
159
+ @storage.attributes(dir).should be_nil
128
160
  end
129
161
  end
data/spec/dir_spec.rb CHANGED
@@ -103,7 +103,12 @@ describe 'Dir' do
103
103
  list.to_set.should be_eql([@path.dir('dir'), @path.file('file')].to_set)
104
104
  end
105
105
 
106
- it "glob search support"
106
+ it "glob search support" do
107
+ @path.dir('dir_a').create
108
+ @path.file('file_a').create
109
+ @path.dir('dir_b').create
110
+ @path.entries('*_a').collect(&:name).sort.should == %w(dir_a file_a)
111
+ end
107
112
 
108
113
  it 'should raise error if trying :entries on file' do
109
114
  @path.file('some_file').create
@@ -125,7 +130,10 @@ describe 'Dir' do
125
130
  @path.include?('non_existing').should be_false
126
131
  end
127
132
 
128
- it 'empty?'
133
+ it 'empty?' do
134
+ @path.empty?.should be_false
135
+ @path.dir('empty_dir').create.empty?.should be_true
136
+ end
129
137
  end
130
138
 
131
139
  describe 'copying' do
data/spec/entry_spec.rb CHANGED
@@ -19,6 +19,7 @@ describe 'Entry' do
19
19
  it 'tmp' do
20
20
  tmp = test_fs.tmp
21
21
  tmp.should be_dir
22
+ tmp.destroy
22
23
 
23
24
  tmp = nil
24
25
  test_fs.tmp do |path|
@@ -28,15 +29,14 @@ describe 'Entry' do
28
29
  tmp.should_not exist
29
30
  end
30
31
 
31
- it 'should respond to local?'
32
-
33
- it 'should respond to host'
34
-
35
- describe 'attributes' do
36
- it 'created_at'
37
-
38
- it 'updated_at'
32
+ it 'should respond to local?' do
33
+ test_fs.should respond_to(:local?)
34
+ end
39
35
 
40
- it 'size'
36
+ it 'created_at, updated_at, size' do
37
+ file = test_fs.file('file').write 'data'
38
+ file.created_at.class.should == Time
39
+ file.updated_at.class.should == Time
40
+ file.size.should == 4
41
41
  end
42
42
  end
data/spec/file_spec.rb CHANGED
@@ -219,6 +219,8 @@ describe 'File' do
219
219
  warn "no :haml template engine, skipping rendering with haml specs"
220
220
  end
221
221
 
222
- it 'size'
222
+ it 'size' do
223
+ @path.file.write('data').size.should == 4
224
+ end
223
225
  end
224
226
  end
data/spec/path_spec.rb CHANGED
@@ -28,7 +28,7 @@ describe "Path" do
28
28
  ) + special).each{|path| Path.should_not be_valid(path)}
29
29
  end
30
30
 
31
- # it 'tmp', focus: true do
31
+ # it 'tmp' do
32
32
  # (Path.new('.') + '..').should == './..'
33
33
  # end
34
34
 
@@ -2,15 +2,23 @@ require 'vfs/storages/local'
2
2
  require 'vfs/storages/specification'
3
3
 
4
4
  describe Vfs::Storages::Local do
5
- it_should_behave_like "vfs storage"
5
+ with_tmp_spec_dir
6
6
 
7
7
  before do
8
- @storage = Vfs::Storages::Local.new
8
+ @storage = Vfs::Storages::Local.new spec_dir
9
+ @storage.open
9
10
  end
10
11
 
11
- describe 'attributes' do
12
- it 'created_at'
13
-
14
- it 'updated_at'
12
+ after do
13
+ @storage.close
15
14
  end
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
24
  end
File without changes
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.14
4
+ version: 0.3.15
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-20 00:00:00.000000000Z
12
+ date: 2011-08-25 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -20,7 +20,6 @@ files:
20
20
  - Rakefile
21
21
  - readme.md
22
22
  - lib/vfs/entries/dir.rb
23
- - lib/vfs/entries/entry/special_attributes.rb
24
23
  - lib/vfs/entries/entry.rb
25
24
  - lib/vfs/entries/file.rb
26
25
  - lib/vfs/entries/universal_entry.rb
@@ -39,6 +38,7 @@ files:
39
38
  - spec/file_spec.rb
40
39
  - spec/path_spec.rb
41
40
  - spec/spec_helper.rb
41
+ - spec/storages/local_spec/emptygit
42
42
  - spec/storages/local_spec.rb
43
43
  - spec/universal_entry_spec.rb
44
44
  homepage: http://github.com/alexeypetrushin/vfs
@@ -1,26 +0,0 @@
1
- module Vfs
2
- class Entry
3
- module SpecialAttributes
4
- def created_at
5
- safe_get :created_at
6
- end
7
-
8
- def updated_at
9
- safe_get :updated_at
10
- end
11
-
12
- protected
13
- def safe_get name
14
- if value = get[name]
15
- value
16
- else
17
- if get[:dir] or get[:file]
18
- raise "attribute :#{name} not supported for #{storage.class}!"
19
- else
20
- raise "entry #{path} not exist!"
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end