Sha256: 844e3b420c07337d285cafac94779fba696d4ecc220744f19c0b5dafd6c17e01

Contents?: true

Size: 1.47 KB

Versions: 22

Compression:

Stored size: 1.47 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

22 entries across 22 versions & 1 rubygems

Version Path
postmark-1.25.1 spec/unit/postmark/client_spec.rb
postmark-1.25.0 spec/unit/postmark/client_spec.rb
postmark-1.24.1 spec/unit/postmark/client_spec.rb
postmark-1.24.0 spec/unit/postmark/client_spec.rb
postmark-1.23.0 spec/unit/postmark/client_spec.rb
postmark-1.22.3 spec/unit/postmark/client_spec.rb
postmark-1.22.2 spec/unit/postmark/client_spec.rb
postmark-1.22.1 spec/unit/postmark/client_spec.rb
postmark-1.22.0 spec/unit/postmark/client_spec.rb
postmark-1.21.8 spec/unit/postmark/client_spec.rb
postmark-1.21.7 spec/unit/postmark/client_spec.rb
postmark-1.21.6 spec/unit/postmark/client_spec.rb
postmark-1.21.5 spec/unit/postmark/client_spec.rb
postmark-1.21.4 spec/unit/postmark/client_spec.rb
postmark-1.21.3 spec/unit/postmark/client_spec.rb
postmark-1.21.2 spec/unit/postmark/client_spec.rb
postmark-1.21.1 spec/unit/postmark/client_spec.rb
postmark-1.21.0 spec/unit/postmark/client_spec.rb
postmark-1.20.0 spec/unit/postmark/client_spec.rb
postmark-1.19.2 spec/unit/postmark/client_spec.rb