Sha256: 46bed71ed6885d134849b2a966c724e0c5ee785fe16bce4b1f7506e927a77dad

Contents?: true

Size: 785 Bytes

Versions: 3

Compression:

Stored size: 785 Bytes

Contents

require "dry-types"

describe "list type argument" do
  before do
    class Test::Foo
      extend Dry::Initializer
      param  :foo, [proc(&:to_s)]
      option :bar, [Dry::Types["strict.string"]]
      option :baz, []
    end
  end

  context "with single items" do
    subject { Test::Foo.new(1, bar: "2", baz: { qux: :QUX }) }

    it "coerces and wraps them to arrays" do
      expect(subject.foo).to eq %w[1]
      expect(subject.bar).to eq %w[2]
      expect(subject.baz).to eq [{ qux: :QUX }]
    end
  end

  context "with arrays" do
    subject { Test::Foo.new([1], bar: %w[2], baz: [{ qux: :QUX }]) }

    it "coerces elements" do
      expect(subject.foo).to eq %w[1]
      expect(subject.bar).to eq %w[2]
      expect(subject.baz).to eq [{ qux: :QUX }]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-initializer-3.0.2 spec/list_type_spec.rb
dry-initializer-3.0.1 spec/list_type_spec.rb
dry-initializer-3.0.0 spec/list_type_spec.rb