Sha256: ab9229390732ccbfae858969fe46ac93044d2ec67245fde393a92f919987bdcf

Contents?: true

Size: 1.94 KB

Versions: 25

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe GrapeSwagger::DocMethods::ParseParams do
  subject { described_class }
  let(:start_value) { -5 }
  let(:end_value) { 5 }

  describe '#parse_range_values' do
    specify do
      parsed_range = subject.send(:parse_range_values, start_value..end_value)
      expect(parsed_range).to eql(minimum: start_value, maximum: end_value)
    end
  end

  describe '#parse_enum_or_range_values' do
    describe 'value as Range' do
      describe 'first Integer' do
        specify do
          parsed_range = subject.send(:parse_enum_or_range_values, start_value..end_value)
          expect(parsed_range).to eql(minimum: start_value, maximum: end_value)
        end
      end

      describe 'first String' do
        specify do
          parsed_range = subject.send(:parse_enum_or_range_values, 'a'..'z')
          expect(parsed_range).to be_nil
        end
      end
    end

    describe 'value as Proc' do
      describe 'as Range' do
        let(:values) { proc { start_value..end_value } }
        specify do
          parsed_range = subject.send(:parse_enum_or_range_values, values)
          expect(parsed_range).to eql(minimum: start_value, maximum: end_value)
        end
      end

      describe 'as Array' do
        let(:values) { proc { %w[a b c] } }
        specify do
          parsed_range = subject.send(:parse_enum_or_range_values, values)
          expect(parsed_range).to eql(enum: %w[a b c])
        end
      end

      describe 'with arity one' do
        let(:values) { proc { |v| v < 25 } }
        specify do
          parsed_range = subject.send(:parse_enum_or_range_values, values)
          expect(parsed_range).to be_nil
        end
      end
    end

    describe 'values as Array -> enums' do
      let(:values) { %w[a b c] }
      specify do
        parsed_range = subject.send(:parse_enum_or_range_values, values)
        expect(parsed_range).to eql(enum: %w[a b c])
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
grape-swagger-1.6.0 spec/lib/parse_params_spec.rb
gitlab-grape-swagger-1.5.0 spec/lib/parse_params_spec.rb
grape-swagger-1.5.0 spec/lib/parse_params_spec.rb
grape-swagger-1.4.2 spec/lib/parse_params_spec.rb
grape-swagger-1.4.1 spec/lib/parse_params_spec.rb
grape-swagger-1.4.0 spec/lib/parse_params_spec.rb
grape-swagger-1.3.1 spec/lib/parse_params_spec.rb
grape-swagger-1.3.0 spec/lib/parse_params_spec.rb
grape-swagger-1.2.1 spec/lib/parse_params_spec.rb
grape-swagger-1.2.0 spec/lib/parse_params_spec.rb
grape-swagger-1.1.0 spec/lib/parse_params_spec.rb
grape-swagger-1.0.0 spec/lib/parse_params_spec.rb
grape-swagger-0.34.2 spec/lib/parse_params_spec.rb
grape-swagger-0.34.1 spec/lib/parse_params_spec.rb
grape-swagger-0.34.0 spec/lib/parse_params_spec.rb
grape-swagger-0.33.0 spec/lib/parse_params_spec.rb
grape-swagger-0.32.1 spec/lib/parse_params_spec.rb
grape-swagger-0.32.0 spec/lib/parse_params_spec.rb
grape-swagger-0.31.1 spec/lib/parse_params_spec.rb
grape-swagger-0.31.0 spec/lib/parse_params_spec.rb