Sha256: f93de91ac0741349eacae50f8d1832a7714c035d8da1855a9552fee8e38f7a99

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

module Swagger
  describe Builder do
    subject(:builder) { described_class.builder }
    describe 'setting fields' do
      it 'raises an error if the field does not exist' do
        expect { builder.xxx = 'foo' }.to raise_error(NoMethodError)
      end

      it 'raises if the value cannot be coerced to match the field' do
        expect { builder.info = 'foo' }.to raise_error(Hashie::CoercionError)
      end

      it 'sets the field' do
        expect { builder.swagger = 2.0 }.to change { builder.swagger }.from(nil).to('2.0')
      end

      it 'allows complex types to be set via a block' do
        builder.info do |info|
          info.title = 'Sample Swagger API'
          info.version = '1.0'
        end

        expect(builder.info).to be_an_kind_of(Swagger::Bash)
        expect(builder.info.title).to eq('Sample Swagger API')
      end
    end

    describe '#build' do
      it 'raises an error if a required field is omitted' do
        expect { builder.build }.to raise_error(ArgumentError, /property '\w+' is required/)
      end

      it 'returns the built Swagger API object if all required fields are present' do
        builder.swagger = 2.0
        builder.info do |info|
          info.title = 'Sample Swagger API'
          info.version = '1.0'
        end
        builder.paths = {
          '/foo' => {}
        }
        builder.paths['/foo'].get do |get|
          get.description = 'Testing...'
          get.tags = %w(foo bar)
        end
        expect(builder.build).to be_an_instance_of(Swagger::V2::API)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
swagger-parser-0.2.6 spec/swagger/builder_spec.rb
swagger-parser-0.2.5 spec/swagger/builder_spec.rb
swagger-core-0.3.0 spec/swagger/builder_spec.rb
swagger-core-0.2.3 spec/swagger/builder_spec.rb
swagger-core-0.2.2 spec/swagger/builder_spec.rb