spec/unit/resync/client/dump_spec.rb in resync-client-0.3.2 vs spec/unit/resync/client/dump_spec.rb in resync-client-0.3.3

- old
+ new

@@ -4,14 +4,14 @@ # TODO: introduce shared examples describe ResourceDump do describe '#zip_packages' do it 'transparently exposes bitstreams' do path = 'spec/data/resourcedump/resourcedump.xml' - package_uri = URI('http://example.com/resourcedump.zip') + package_uri = URI('http://example.com/bitstream-package.zip') client = instance_double(Client) - expect(client).to receive(:download_to_temp_file).once.with(package_uri).and_return('spec/data/resourcedump/resourcedump.zip') + expect(client).to receive(:download_to_temp_file).once.with(package_uri).and_return('spec/data/resourcedump/bitstream-package.zip') dump = XMLParser.parse(File.read(path)) dump.client = client zip_packages = dump.zip_packages @@ -79,25 +79,28 @@ end end end describe '#all_zip_packages' do - it 'is an alias for #zip_packages' do + it 'delegates to #zip_packages, lazily' do path = 'spec/data/resourcedump/resourcedump.xml' - package_uri = URI('http://example.com/resourcedump.zip') + package_uri = URI('http://example.com/bitstream-package.zip') client = instance_double(Client) - expect(client).to receive(:download_to_temp_file).once.with(package_uri).and_return('spec/data/resourcedump/resourcedump.zip') + expect(client).to receive(:download_to_temp_file).once.with(package_uri).and_return('spec/data/resourcedump/bitstream-package.zip') dump = XMLParser.parse(File.read(path)) dump.client = client all_zip_packages = dump.all_zip_packages - expect(all_zip_packages.size).to eq(1) - expect(all_zip_packages[0]).to be_a(Client::Zip::ZipPackage) + expect(all_zip_packages).to be_a(Enumerator::Lazy) - bitstreams = all_zip_packages[0].bitstreams + all_zip_packages_array = all_zip_packages.to_a + expect(all_zip_packages_array.size).to eq(1) + expect(all_zip_packages_array[0]).to be_a(Client::Zip::ZipPackage) + + bitstreams = all_zip_packages_array[0].bitstreams expect(bitstreams.size).to eq(2) expect(bitstreams[0].content).to eq(File.read('spec/data/resourcedump/resources/res1')) expect(bitstreams[1].content).to eq(File.read('spec/data/resourcedump/resources/res2')) end end @@ -108,11 +111,11 @@ it 'transparently exposes bitstreams' do path = 'spec/data/resourcedump/changedump.xml' package_uri = URI('http://example.com/changedump.zip') client = instance_double(Client) - expect(client).to receive(:download_to_temp_file).once.with(package_uri).and_return('spec/data/resourcedump/resourcedump.zip') + expect(client).to receive(:download_to_temp_file).once.with(package_uri).and_return('spec/data/resourcedump/bitstream-package.zip') dump = XMLParser.parse(File.read(path)) dump.client = client zip_packages = dump.zip_packages @@ -180,24 +183,27 @@ end end end describe '#all_zip_packages' do - it 'is an alias for #zip_packages' do + it 'delegates to #zip_packages, lazily' do path = 'spec/data/resourcedump/changedump.xml' package_uri = URI('http://example.com/changedump.zip') client = instance_double(Client) - expect(client).to receive(:download_to_temp_file).once.with(package_uri).and_return('spec/data/resourcedump/resourcedump.zip') + expect(client).to receive(:download_to_temp_file).once.with(package_uri).and_return('spec/data/resourcedump/bitstream-package.zip') dump = XMLParser.parse(File.read(path)) dump.client = client - zip_packages = dump.all_zip_packages - expect(zip_packages.size).to eq(1) - expect(zip_packages[0]).to be_a(Client::Zip::ZipPackage) + all_zip_packages = dump.all_zip_packages + expect(all_zip_packages).to be_a(Enumerator::Lazy) - bitstreams = zip_packages[0].bitstreams + all_zip_packages_array = all_zip_packages.to_a + expect(all_zip_packages_array.size).to eq(1) + expect(all_zip_packages_array[0]).to be_a(Client::Zip::ZipPackage) + + bitstreams = all_zip_packages_array[0].bitstreams expect(bitstreams.size).to eq(2) expect(bitstreams[0].content).to eq(File.read('spec/data/resourcedump/resources/res1')) expect(bitstreams[1].content).to eq(File.read('spec/data/resourcedump/resources/res2')) end end