Sha256: e449ee10111d5cfb915b163424f96d2895d2b13eb8e03f9108b1d200da5f416d

Contents?: true

Size: 907 Bytes

Versions: 3

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

describe Grape::Validations::Types::ArrayCoercer do
  subject { described_class.new(type) }

  describe '#call' do
    context 'an array of primitives' do
      let(:type) { Array[String] }

      it 'coerces elements in the array' do
        expect(subject.call([10, 20])).to eq(%w[10 20])
      end
    end

    context 'an array of arrays' do
      let(:type) { Array[Array[Integer]] }

      it 'coerces elements in the nested array' do
        expect(subject.call([%w[10 20]])).to eq([[10, 20]])
        expect(subject.call([['10'], ['20']])).to eq([[10], [20]])
      end
    end

    context 'an array of sets' do
      let(:type) { Array[Set[Integer]] }

      it 'coerces elements in the nested set' do
        expect(subject.call([%w[10 20]])).to eq([Set[10, 20]])
        expect(subject.call([['10'], ['20']])).to eq([Set[10], Set[20]])
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-1.8.0 spec/grape/validations/types/array_coercer_spec.rb
grape-1.7.1 spec/grape/validations/types/array_coercer_spec.rb
grape-1.7.0 spec/grape/validations/types/array_coercer_spec.rb