Sha256: e06e0b7e6a5719939cc39812c2e3210214f4fabbdb9d84acd0e91f89d14b3858

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'

module Resync
  describe ZipPackages do
    it 'is lazy' do
      resources = Array.new(3) { |i| Resource.new(uri: "http://example.org/res#{i}") }

      zip_packages = ZipPackages.new(resources)

      zip_package = instance_double(ZipPackage)
      expect(resources[0]).not_to receive(:zip_package)
      expect(resources[1]).not_to receive(:zip_package)
      expect(resources[2]).to receive(:zip_package).and_return(zip_package)

      expect(zip_packages[2]).to be(zip_package)
    end

    it 'caches zip packages' do
      resources = Array.new(3) { |i| Resource.new(uri: "http://example.org/res#{i}") }

      zip_packages = ZipPackages.new(resources)

      zip_package = instance_double(ZipPackage)
      expect(resources[1]).to receive(:zip_package).once.and_return(zip_package)

      expect(zip_packages[1]).to be(zip_package)
      expect(zip_packages[1]).to be(zip_package)
    end

    it 'supports lazy iteration' do
      manifests = Array.new(3) { instance_double(ChangeDumpManifest) }
      all_packages = Array.new(3) do |index|
        zip_package = instance_double(ZipPackage)
        allow(zip_package).to receive(:manifest).and_return(manifests[index])
        zip_package
      end
      resources = Array.new(3) do |index|
        resource = Resource.new(uri: "http://example.org/res#{index}")
        if index > 1
          expect(resource).not_to receive(:zip_package)
        else
          expect(resource).to receive(:zip_package).and_return(all_packages[index])
        end
        resource
      end

      zip_packages = ZipPackages.new(resources)
      zip_packages.each_with_index do |zip_package, index|
        expect(zip_package.manifest).to be(manifests[index])
        break if index >= 1
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
resync-client-0.1.2 spec/unit/resync/client/zip_packages_spec.rb