lib/vfs/storages/specification.rb in vfs-0.3.14 vs lib/vfs/storages/specification.rb in vfs-0.3.15
- old
+ new
@@ -1,129 +1,161 @@
-# use '$ gem install ruby_ext' to install.
require 'rspec_ext'
require 'ruby_ext'
-shared_examples_for 'vfs storage' do
- before do
- @storage.open_fs do |fs|
- @tmp_dir = fs.tmp
- end
+shared_examples_for 'vfs storage basic' do
+ it 'should respond to :local?' do
+ @storage.should respond_to(:local?)
end
- after do
- @storage.open_fs do |fs|
- attrs = fs.attributes(@tmp_dir)
- fs.delete_dir @tmp_dir if attrs && attrs[:dir]
- end
+ it "should provide open method" do
+ @storage.open
+ @storage.open{'result'}.should == 'result'
end
+end
- it 'should respond to :local?' do
- @storage.open_fs{|fs| fs.should respond_to(:local?)}
+shared_examples_for 'vfs storage attributes basic' do
+ it 'should have root dir' do
+ attrs = @storage.attributes('/')
+ attrs[:dir].should be_true
+ attrs[:file].should be_false
end
- it 'should respond to :host'
+ it "attributes should return nil if there's no entry" do
+ @storage.attributes('/non_existing_entry').should be_nil
+ end
+end
- it 'should have root dir' do
- @storage.open_fs do |fs|
- fs.attributes('/').subset(:file, :dir).should == {file: false, dir: true}
- end
+shared_examples_for 'vfs storage files' do
+ it "file attributes" do
+ @storage.attributes('/file').should be_nil
+
+ @storage.write_file('/file', false){|w| w.write 'something'}
+ attrs = @storage.attributes('/file')
+ attrs[:file].should be_true
+ attrs[:dir].should be_false
end
- describe "files" do
- before do
- @remote_file = "#{@tmp_dir}/remote_file"
- end
+ it "read, write, append" do
+ # write
+ @storage.write_file('/file', false){|w| w.write 'something'}
+ @storage.attributes('/file')[:file].should == true
- it "file attributes" do
- @storage.open_fs do |fs|
- fs.attributes(@remote_file).should == {}
- fs.write_file(@remote_file, false){|w| w.write 'something'}
- attrs = fs.attributes(@remote_file)
- fs.attributes(@remote_file).subset(:file, :dir).should == {file: true, dir: false}
- end
- end
+ # read
+ data = ""
+ @storage.read_file('/file'){|buff| data << buff}
+ data.should == 'something'
- it "read, write & append" do
- @storage.open_fs do |fs|
- fs.write_file(@remote_file, false){|w| w.write 'something'}
- fs.attributes(@remote_file)[:file].should be_true
+ # append
+ @storage.write_file('/file', true){|w| w.write ' another'}
+ data = ""
+ @storage.read_file('/file'){|buff| data << buff}
+ data.should == 'something another'
+ end
- data = ""
- fs.read_file(@remote_file){|buff| data << buff}
- data.should == 'something'
+ it "delete_file" do
+ @storage.write_file('/file', false){|w| w.write 'something'}
+ @storage.attributes('/file')[:file].should be_true
+ @storage.delete_file('/file')
+ @storage.attributes('/file').should be_nil
+ end
+end
- # append
- fs.write_file(@remote_file, true){|w| w.write ' another'}
- data = ""
- fs.read_file(@remote_file){|buff| data << buff}
- data.should == 'something another'
- end
- end
+shared_examples_for 'vfs storage full attributes for files' do
+ it "attributes for files" do
+ @storage.write_file('/file', false){|w| w.write 'something'}
+ attrs = @storage.attributes('/file')
+ attrs[:file].should be_true
+ attrs[:dir].should be_false
+ attrs[:created_at].class.should == Time
+ attrs[:updated_at].class.should == Time
+ attrs[:size].should == 9
+ end
+end
- it "delete_file" do
- @storage.open_fs do |fs|
- fs.write_file(@remote_file, false){|w| w.write 'something'}
- fs.attributes(@remote_file)[:file].should be_true
- fs.delete_file(@remote_file)
- fs.attributes(@remote_file).should == {}
- end
- end
+shared_examples_for 'vfs storage dirs' do
+ it "directory crud" do
+ @storage.attributes('/dir').should be_nil
+
+ @storage.create_dir('/dir')
+ attrs = @storage.attributes('/dir')
+ attrs[:file].should be_false
+ attrs[:dir].should be_true
+
+ @storage.delete_dir('/dir')
+ @storage.attributes('/dir').should be_nil
end
- describe 'directories' do
- # before do
- # @from_local, @remote_path, @to_local = "#{@local_dir}/dir", "#{@tmp_dir}/upload", "#{@local_dir}/download"
- # end
+ it 'should delete not-empty directories' do
+ @storage.create_dir('/dir')
+ @storage.create_dir('/dir/dir2')
+ @storage.write_file('/dir/dir2/file', false){|w| w.write 'something'}
+ @storage.attributes('/dir').should_not be_nil
- before do
- @remote_dir = "#{@tmp_dir}/some_dir"
- end
+ @storage.delete_dir('/dir')
+ @storage.attributes('/dir').should be_nil
+ end
- it "directory_exist?, create_dir, delete_dir" do
- @storage.open_fs do |fs|
- fs.attributes(@remote_dir).should == {}
- fs.create_dir(@remote_dir)
- fs.attributes(@remote_dir).subset(:file, :dir).should == {file: false, dir: true}
- fs.delete_dir(@remote_dir)
- fs.attributes(@remote_dir).should == {}
- end
- end
+ it 'each' do
+ -> {@storage.each_entry('/not_existing_dir', nil){|path, type| list[path] = type}}.should raise_error
- it 'should delete not-empty directories' do
- @storage.open_fs do |fs|
- fs.create_dir(@remote_dir)
- fs.create_dir("#{@remote_dir}/dir")
- fs.write_file("#{@remote_dir}/dir/file", false){|w| w.write 'something'}
- fs.delete_dir(@remote_dir)
- fs.attributes(@remote_dir).should == {}
- end
- end
+ @storage.create_dir '/dir'
+ @storage.create_dir('/dir/dir2')
+ @storage.write_file('/dir/file', false){|w| w.write 'something'}
- it 'each' do
- @storage.open_fs do |fs|
- list = {}
- fs.each_entry(@tmp_dir, nil){|path, type| list[path] = type}
- list.should be_empty
+ list = {}
+ @storage.each_entry('/dir', nil){|path, type| list[path] = type}
+ list.should == {'dir2' => :dir, 'file' => :file}
+ end
- dir, file = "#{@tmp_dir}/dir", "#{@tmp_dir}/file"
- fs.create_dir(dir)
- fs.write_file(file, false){|w| w.write 'something'}
+ # it "upload_directory & download_directory" do
+ # upload_path_check = "#{@remote_path}/dir2/file"
+ # check_attributes upload_path_check, nil
+ # @storage.upload_directory(@from_local, @remote_path)
+ # check_attributes upload_path_check, file: true, dir: false
+ #
+ # download_path_check = "#{@to_local}/dir2/file"
+ # File.exist?(download_path_check).should be_false
+ # @storage.download_directory(@remote_path, @to_local)
+ # File.exist?(download_path_check).should be_true
+ # end
+end
- list = {}
- fs.each_entry(@tmp_dir, nil){|path, type| list[path] = type}
- list.should == {'dir' => :dir, 'file' => :file}
- end
- end
+shared_examples_for 'vfs storage query' do
+ it 'each with query' do
+ @storage.create_dir '/dir'
+ @storage.create_dir('/dir/dir_a')
+ @storage.create_dir('/dir/dir_b')
+ @storage.write_file('/dir/file_a', false){|w| w.write 'something'}
- # it "upload_directory & download_directory" do
- # upload_path_check = "#{@remote_path}/dir2/file"
- # check_attributes upload_path_check, nil
- # fs.upload_directory(@from_local, @remote_path)
- # check_attributes upload_path_check, file: true, dir: false
- #
- # download_path_check = "#{@to_local}/dir2/file"
- # File.exist?(download_path_check).should be_false
- # fs.download_directory(@remote_path, @to_local)
- # File.exist?(download_path_check).should be_true
- # end
+ list = {}
+ @storage.each_entry('/dir', '*_a'){|path, type| list[path] = type}
+ list.should == {'dir_a' => :dir, 'file_a' => :file}
+ end
+end
+
+shared_examples_for 'vfs storage full attributes for dirs' do
+ it "attributes for dirs" do
+ @storage.create_dir('/dir')
+ attrs = @storage.attributes('/dir')
+ attrs[:file].should be_false
+ attrs[:dir].should be_true
+ attrs[:created_at].class.should == Time
+ attrs[:updated_at].class.should == Time
+ attrs.should_not include(:size)
+ end
+end
+
+shared_examples_for 'vfs storage tmp dir' do
+ it "tmp dir" do
+ dir = @storage.tmp
+ @storage.attributes(dir).should_not be_nil
+ @storage.delete_dir dir
+ @storage.attributes(dir).should be_nil
+
+ dir = nil
+ @storage.tmp do |tmp_dir|
+ dir = tmp_dir
+ @storage.attributes(dir).should_not be_nil
+ end
+ @storage.attributes(dir).should be_nil
end
end
\ No newline at end of file