require 'spec_helper' module Nestene describe FileNameConverter do describe '#key_to_file_name' do it "should convert non-charater in the file name to hex-escaped version" do expect(subject.key_to_file_name('test_-+/')).to eq('test_5f_2d_2b_2f') end end describe '#file_name_to_key' do it "should convert hex-escaped version of the file name to the original" do expect(subject.file_name_to_key('test_5f_2d_2b_2f')).to eq('test_-+/') end end end describe DiskStorage do let(:tmpdir) {Dir.mktmpdir} after{FileUtils.remove_entry_secure tmpdir} describe :list do subject {DiskStorage.new(tmpdir)} context "when there is nothing in the storage" do it "should return empty list" do expect(subject.list).to eq([]) end end context "when there is at least one object in the storage" do before {subject.store("test",{})} it "should return list of existing objects" do expect(subject.list).to eq(['test']) end end end describe :load do subject {DiskStorage.new(tmpdir)} context "when the object does not exist" do it "should return nil" do expect(subject.load('whatever')).to be_nil end end context "when the object exists" do before {subject.store('test',{})} it "should return object's structure" do expect(subject.load('test')).to eq({}) end end end describe :store do subject {DiskStorage.new(tmpdir)} it "stores structure" do subject.store('test',{}) expect(subject.load('test')).to eq({}) end end end describe MemoryStorage do describe :list do subject {MemoryStorage.new} context "when there is nothing in the storage" do it "should return empty list" do expect(subject.list).to eq([]) end end context "when there is at least one object in the storage" do before {subject.store("test",{})} it "should return list of existing objects" do expect(subject.list).to eq(['test']) end end end describe :load do subject {MemoryStorage.new} context "when the object does not exist" do it "should return nil" do expect(subject.load('whatever')).to be_nil end end context "when the object exists" do before {subject.store('test',{})} it "should return object's structure" do expect(subject.load('test')).to eq({}) end end end describe :store do subject {MemoryStorage.new} it "stores structure" do subject.store('test',{}) expect(subject.load('test')).to eq({}) end end end end