spec/nestene/storage_spec.rb in nestene-0.2.0 vs spec/nestene/storage_spec.rb in nestene-0.2.1

- old
+ new

@@ -21,14 +21,14 @@ let(:tmpdir) {Dir.mktmpdir} after{FileUtils.remove_entry_secure tmpdir} + subject {DiskStorage.new(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 @@ -42,12 +42,10 @@ 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 @@ -60,44 +58,57 @@ end end describe :store do - subject {DiskStorage.new(tmpdir)} - - it "stores structure" do + it "should store structure" do subject.store('test',{}) expect(subject.load('test')).to eq({}) end + + context "when structure is nil" do + it 'should delete the entry' do + subject.store('test',{}) + subject.store('test',nil) + expect(subject.load('test')).to eq(nil) + expect(subject.list).to_not include('test') + end + end end + describe :delete do + it "deletes existing strucuture" do + subject.store('test',{}) + subject.delete('test') + expect(subject.load('test')).to eq(nil) + expect(subject.list).to_not include('test') + end + end + end describe MemoryStorage do - describe :list do - subject {MemoryStorage.new} + subject {MemoryStorage.new} + describe :list do + 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 @@ -106,19 +117,35 @@ 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 + it "should store structure" do subject.store('test',{}) expect(subject.load('test')).to eq({}) + end + + context "when structure is nil" do + it 'should delete the entry' do + subject.store('test',{}) + subject.store('test',nil) + expect(subject.load('test')).to eq(nil) + expect(subject.list).to_not include('test') + end + end + + end + + describe :delete do + it "deletes existing strucuture" do + subject.store('test',{}) + subject.delete('test') + expect(subject.load('test')).to eq(nil) + expect(subject.list).to_not include('test') end end end end \ No newline at end of file