spec/integration/folder_operations_spec.rb in rmega-0.1.7 vs spec/integration/folder_operations_spec.rb in rmega-0.2.0
- old
+ new
@@ -3,60 +3,60 @@
describe 'Folders operations' do
if account_file_exists?
before(:all) do
- @name = "folder_#{rand.denominator}_#{rand.denominator}"
- @sub_folder_name = "folder_#{rand.denominator}_#{rand.denominator}"
@storage = login
end
- # Note: node searching is traversal
- def find_folder(name)
- @storage.nodes.find { |f| f.type == :folder && f.name == name }
- end
+ let(:name) { "test_folder" }
context 'when #create_folder is called on a node' do
+ before do
+ @folder = @storage.root.create_folder(name)
+ end
+
it 'creates a new folder under that node' do
- folder = @storage.root.create_folder(@name)
- expect(folder.name).to eql @name
- expect(folder.parent_handle).to eq @storage.root.handle
+ expect(@folder.name).to eql name
+ expect(@folder.parent_handle).to eq @storage.root.handle
end
+
+ after do
+ @folder.delete
+ end
end
- context 'searching for a folder by its name' do
+ context 'searching for a folder by its handle' do
+ before do
+ @folder = @storage.root.create_folder(name)
+ end
it 'returns the matching folder' do
- expect(find_folder(@name).name).to eql @name
+ found_node = @storage.nodes.find { |n| n.handle == @folder.handle }
+ expect(found_node).not_to be_nil
end
- end
- context "when #create_folder under created folder" do
-
- it "creates a new folder under created folder" do
- parent_folder = find_folder(@name)
-
- sub_folder = parent_folder.create_folder(@sub_folder_name)
-
- expect(parent_folder.folders.first.name).to eql @sub_folder_name
- expect(sub_folder.parent_handle).to eql parent_folder.handle
+ after do
+ @folder.delete
end
end
- context 'when #delete is called on a folder node' do
-
- it 'deletes sub folder' do
- expect(find_folder(@sub_folder_name).delete).to eql 0
+ context 'when #create_folder under created folder' do
+ before do
+ @folder = @storage.root.create_folder(name)
+ @sub_folder = @folder.create_folder(name)
end
- it 'deletes the folder' do
- expect(find_folder(@name).delete).to eql 0
+ it 'creates a new folder under created folder' do
+ found_node = @storage.nodes.find { |n| n.handle == @sub_folder.handle }
+ expect(found_node.parent_handle).to eq(@folder.handle)
end
- it 'does not find the folder (and its subfolder) anymore' do
- expect(find_folder(@name)).to be_nil
- expect(find_folder(@sub_folder_name)).to be_nil
+ after do
+ @folder.delete
+ found_node = @storage.nodes.find { |n| n.handle == @sub_folder.handle }
+ expect(found_node).to be_nil
end
end
end
end