Sha256: e204c167362323df309c60473c89288d52ed3b72b78d1a29b35f83ebbb9828bd

Contents?: true

Size: 588 Bytes

Versions: 8

Compression:

Stored size: 588 Bytes

Contents

require "dry-types"

describe "value coercion via dry-types" do
  before do
    module Test::Types
      include Dry::Types.module
    end

    class Test::Foo
      extend Dry::Initializer

      param  :foo, type: Test::Types::Coercible::String
      option :bar, proc(&:to_i), default: proc { "16" }
    end
  end

  it "coerces assigned values" do
    subject = Test::Foo.new :foo, bar: "13"

    expect(subject.foo).to eql "foo"
    expect(subject.bar).to eql 13
  end

  it "coerces defaults as well" do
    subject = Test::Foo.new :foo

    expect(subject.bar).to eql 16
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dry-initializer-3.0.1 spec/value_coercion_via_dry_types_spec.rb
dry-initializer-3.0.0 spec/value_coercion_via_dry_types_spec.rb
dry-initializer-2.5.0 spec/value_coercion_via_dry_types_spec.rb
dry-initializer-2.4.0 spec/value_coercion_via_dry_types_spec.rb
dry-initializer-2.3.0 spec/value_coercion_via_dry_types_spec.rb
dry-initializer-2.2.0 spec/value_coercion_via_dry_types_spec.rb
dry-initializer-2.1.0 spec/value_coercion_via_dry_types_spec.rb
dry-initializer-2.0.0 spec/value_coercion_via_dry_types_spec.rb