Sha256: 12cfb4a44ec45cbf5166e6b748adb065963bfc941ab59479f6b6e43186bc6917

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe GrapeSwagger::DocMethods::OptionalObject do
  subject { described_class }

  specify { expect(subject).to eql GrapeSwagger::DocMethods::OptionalObject }
  specify { expect(subject).to respond_to :build }

  describe 'build' do
    let(:key) { :host }
    let!(:request) { Rack::Request.new(Rack::MockRequest.env_for('http://example.com:8080/')) }

    describe 'no option given for host, take from request' do
      let(:options) { { foo: 'foo' } }
      specify do
        expect(subject.build(key, options, request)).to eql request.host_with_port
      end
    end

    let(:value) { 'grape-swagger.example.com' }

    describe 'option is a string' do
      let(:options) { { host: value } }
      specify do
        expect(subject.build(key, options, request)).to eql value
      end
    end

    describe 'option is a lambda' do
      let(:options) { { host: -> { value } } }
      specify do
        expect(subject.build(key, options, request)).to eql value
      end
    end

    describe 'option is a proc' do
      # rubocop:disable RegexpMatch
      let(:options) do
        { host: proc { |request| request.host =~ /^example/ ? '/api-example' : '/api' } }
      end
      # rubocop:enable RegexpMatch
      specify do
        expect(subject.build(key, options, request)).to eql '/api-example'
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
grape-swagger-0.32.1 spec/lib/optional_object_spec.rb
grape-swagger-0.32.0 spec/lib/optional_object_spec.rb
grape-swagger-0.31.1 spec/lib/optional_object_spec.rb
grape-swagger-0.31.0 spec/lib/optional_object_spec.rb
grape-swagger-0.30.1 spec/lib/optional_object_spec.rb
grape-swagger-0.30.0 spec/lib/optional_object_spec.rb
grape-swagger-0.29.0 spec/lib/optional_object_spec.rb
grape-swagger-0.28.0 spec/lib/optional_object_spec.rb