Sha256: d207e21e4ca4fe8ad71e0ddf7dd777316bcb47ca15c9d9330570219f4bd0a781

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

# -*- encoding : utf-8 -*-
module Pacto
  module Generator
    describe SwaggerContractFactory do
      let(:swagger_file) { 'spec/fixtures/swagger/petstore.yaml' }
      let(:expected_schema) do
        {
          'type' => 'array',
          'items' => {
            'required' => %w(id name),
            'properties' => {
              'id' => { 'type' => 'integer', 'format' => 'int64' },
              'name' => { 'type' => 'string' },
              'tag' => { 'type' => 'string' }
            }
          }
        }
      end
      describe '#load_hints' do
        it 'loads hints from Swagger' do
          hints = subject.load_hints(swagger_file)
          expect(hints.size).to eq(3) # number of API operations
          hints.each do | hint |
            expect(hint).to be_a_kind_of(Pacto::Generator::Hint)
            expect(hint.host).to eq('petstore.swagger.wordnik.com')
            expect([:get, :post]).to include(hint.http_method)
            expect(hint.path).to match(/\/pets/)
          end
        end
      end

      describe '#build_from_file' do
        it 'loads Contracts from Swagger' do
          contracts = subject.build_from_file(swagger_file)
          expect(contracts.size).to eq(3) # number of API operations
          contracts.each do | contract |
            expect(contract).to be_a_kind_of(Pacto::Contract)

            request_clause = contract.request
            expect(request_clause.host).to eq('petstore.swagger.wordnik.com')
            expect([:get, :post]).to include(request_clause.http_method)
            expect(request_clause.path).to match(/\/pets/)

            response_clause = contract.response
            if request_clause.http_method == :get
              expect(response_clause.status).to eq(200)
            else
              expect(response_clause.status).to eq(201)
            end
            expect(response_clause.schema).to eq(expected_schema) if response_clause.status == 200
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pacto-0.4.0.rc1 spec/unit/pacto/swagger_contract_factory_spec.rb