spec/lib/aggro/file_store/writer_spec.rb in aggro-0.0.3 vs spec/lib/aggro/file_store/writer_spec.rb in aggro-0.0.4

- old
+ new

@@ -24,17 +24,18 @@ it 'should write an offsets to the index file for each event' do writer.write(events) index_io.rewind - offsets = ObjectStream.new(index_io, type: 'marshal').to_a + offsets = MarshalStream.new(index_io).to_a expect(offsets.length).to eq 2 end context 'when files already contain data' do let(:existing_event) { Event.new 'tested_pizza', Time.new(2014), data } - let(:data_content) { EventSerializer.serialize(existing_event) } + let(:raw_content) { EventSerializer.serialize(existing_event) } + let(:data_content) { Marshal.dump raw_content } let(:index_content) { Marshal.dump data_content.bytesize } it 'should write event data to the data file' do writer.write(events) @@ -44,23 +45,25 @@ it 'should write an offsets to the index file for each event' do writer.write(events) index_io.rewind - offsets = ObjectStream.new(index_io, type: 'marshal').to_a + offsets = MarshalStream.new(index_io).to_a expect(offsets.length).to eq 3 end it 'should write corrent offsets for each event' do writer.write(events) index_io.rewind - offsets = ObjectStream.new(index_io, type: 'marshal').to_a + offsets = MarshalStream.new(index_io).to_a expect do - EventSerializer.deserialize data_content[0...(offsets[0])] - EventSerializer.deserialize data_content[offsets[0]...offsets[1]] - EventSerializer.deserialize data_content[offsets[1]...offsets[2]] + [ + data_content[0...(offsets[0])], + data_content[offsets[0]...offsets[1]], + data_content[offsets[1]...offsets[2]] + ].each { |data| EventSerializer.deserialize Marshal.load(data) } end.to_not raise_error end end end end