Sha256: c2d2028dfd693e195a7474f93a1416ec5b5ecb8fed93e662dae4c7bf7815c89a

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

module Pacto
  describe ResponseClause do
    let(:body_definition) do
      {
        :type => 'object',
        :required => true,
        :properties => double('body definition properties')
      }
    end

    let(:definition) do
      {
        'status' => 200,
        'headers' => {
          'Content-Type' => 'application/json'
        },
        'body' => body_definition
      }
    end

    subject(:response) { ResponseClause.new(definition) }

    it 'has a status' do
      expect(response.status).to eq(200)
    end

    it 'has a headers hash' do
      expect(response.headers).to eq(
        'Content-Type' => 'application/json'
      )
    end

    it 'has a schema' do
      expect(response.schema).to eq(body_definition)
    end

    it 'has a default value for the schema' do
      response = ResponseClause.new(definition.merge('body' => nil))
      expect(response.schema).to eq(Hash.new)
    end

    describe 'the response body' do
      let(:generated_body) { double }

      it 'is the json generated from the schema' do
        JSON::Generator.should_receive(:generate).
          with(definition['body']).
          and_return(generated_body)

        expect(response.body).to eq(generated_body)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pacto-0.3.1 spec/unit/pacto/response_clause_spec.rb
pacto-0.3.0 spec/unit/pacto/response_clause_spec.rb