Sha256: 75417812866859bb2cf806c7e1af4d77fc14497efdcce8b34dcbc1f91d3df474

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 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
      specify do
        expect(subject.build(key, options, request)).to eql '/api-example'
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
grape-swagger-0.27.3 spec/lib/optional_object_spec.rb
grape-swagger-0.27.2 spec/lib/optional_object_spec.rb
grape-swagger-0.27.1 spec/lib/optional_object_spec.rb
grape-swagger-0.27.0 spec/lib/optional_object_spec.rb