Sha256: 699f08a0d27e0c02cae89e8f8d7bc2bbc24341c2f5b5f3256a3bddaa7fcc8b52

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

# -*- encoding : utf-8 -*-
require_relative '../../../../lib/pacto/core/contract_registry'

module Pacto
  describe ContractRegistry do
    let(:contract) { Fabricate(:contract) }
    let(:request_signature) { Fabricate(:webmock_request_signature) }

    subject(:contract_registry) do
      ContractRegistry.new
    end

    describe '.register' do
      it 'registers the contract' do
        contract_registry.register contract
        expect(contract_registry).to include(contract)
      end
    end

    describe '.contracts_for' do
      before(:each) do
        contract_registry.register contract
      end

      context 'when no contracts are found for a request' do
        it 'returns an empty list' do
          expect(contract).to receive(:matches?).with(request_signature).and_return false
          expect(contract_registry.contracts_for request_signature).to be_empty
        end
      end

      context 'when contracts are found for a request' do
        it 'returns the matching contracts' do
          expect(contract).to receive(:matches?).with(request_signature).and_return true
          expect(contract_registry.contracts_for request_signature).to eq([contract])
        end
      end
    end

    def create_contracts(total, matches)
      total.times.map do
        double('contract',
               :stub_contract! => double('request matcher'),
               :matches? => matches)
      end
    end

    def register_contracts(contracts)
      contracts.each { |contract| contract_registry.register contract }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pacto-0.4.0.rc3 spec/unit/pacto/core/contract_registry_spec.rb
pacto-0.4.0.rc2 spec/unit/pacto/core/contract_registry_spec.rb
pacto-0.4.0.rc1 spec/unit/pacto/core/contract_registry_spec.rb