Sha256: 8c4a91312a8073643e0ac55d8a4d24de510e60a897567cd1fb1b45dfeb20a322

Contents?: true

Size: 1.48 KB

Versions: 25

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe Postmark::Client do

  subject { Postmark::Client.new('abcd-efgh') }

  describe 'instance' do

    describe '#find_each' do

      let(:path) { 'resources' }
      let(:name) { 'Resources' }
      let(:response) {
        {
          'TotalCount' => 10,
          name => [{'Foo' => 'bar'}, {'Bar' => 'foo'}]
        }
      }

      it 'returns an enumerator' do
        expect(subject.find_each(path, name)).to be_kind_of(Enumerable)
      end

      it 'can be iterated' do
        collection = [{:foo => 'bar'}, {:bar => 'foo'}].cycle(5)
        allow(subject.http_client).
            to receive(:get).with(path, an_instance_of(Hash)).
                             exactly(5).times.and_return(response)
        expect { |b| subject.find_each(path, name, :count => 2).each(&b) }.
            to yield_successive_args(*collection)
      end

      # Only Ruby >= 2.0.0 supports Enumerator#size
      it 'lazily calculates the collection size',
        :skip_ruby_version => ['1.8.7', '1.9'] do
        allow(subject.http_client).
            to receive(:get).exactly(1).times.and_return(response)
        collection = subject.find_each(path, name, :count => 2)
        expect(collection.size).to eq(10)
      end

      it 'iterates over the collection to count it' do
        allow(subject.http_client).
            to receive(:get).exactly(5).times.and_return(response)
        expect(subject.find_each(path, name, :count => 2).count).to eq(10)
      end

    end

  end

end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
postmark-1.18.0 spec/unit/postmark/client_spec.rb
postmark-1.17.0 spec/unit/postmark/client_spec.rb
postmark-1.16.0 spec/unit/postmark/client_spec.rb
postmark-1.15.0 spec/unit/postmark/client_spec.rb
postmark-1.14.0 spec/unit/postmark/client_spec.rb
postmark-1.13.0 spec/unit/postmark/client_spec.rb
postmark-1.12.0 spec/unit/postmark/client_spec.rb
postmark-1.11.0 spec/unit/postmark/client_spec.rb
postmark-1.10.0 spec/unit/postmark/client_spec.rb
postmark-1.9.1 spec/unit/postmark/client_spec.rb
postmark-1.9.0 spec/unit/postmark/client_spec.rb
postmark-1.8.1 spec/unit/postmark/client_spec.rb
postmark-1.8.0 spec/unit/postmark/client_spec.rb
postmark-1.7.1 spec/unit/postmark/client_spec.rb
postmark-1.7.0 spec/unit/postmark/client_spec.rb
postmark-1.6.0 spec/unit/postmark/client_spec.rb
postmark-1.5.0 spec/unit/postmark/client_spec.rb
postmark-1.4.3 spec/unit/postmark/client_spec.rb
postmark-1.4.2 spec/unit/postmark/client_spec.rb
postmark-1.4.1 spec/unit/postmark/client_spec.rb