Sha256: 03e78f006f74519aac9f3506b8f8b835ee65b1d500c4cdc1ca7986f30f93b650

Contents?: true

Size: 733 Bytes

Versions: 18

Compression:

Stored size: 733 Bytes

Contents

RSpec.describe 'Extending DSL' do
  it 'allows configuring custom DSL methods' do
    dsl_ext = Module.new do
      def maybe_int(name, *predicates, &block)
        required(name, [:nil, :int]).maybe(:int?, *predicates, &block)
      end
    end

    Dry::Validation::Schema.configure do |config|
      config.dsl_extensions = dsl_ext
    end

    schema = Dry::Validation.Schema do
      configure do
        config.input_processor = :form
        config.type_specs = true
      end

      maybe_int(:age)
    end

    expect(schema.(age: nil)).to be_success
    expect(schema.(age: 1)).to be_success
    expect(schema.(age: '1')).to be_success
    expect(schema.(age: 'foo').messages).to eql(age: ['must be an integer'])
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dry-validation-0.11.2 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.11.1 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.11.0 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.10.7 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.10.6 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.10.5 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.10.4 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.10.3 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.10.2 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.10.1 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.10.0 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.9.5 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.9.4 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.9.3 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.9.2 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.9.1 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.9.0 spec/integration/schema/extending_dsl_spec.rb
dry-validation-0.8.0 spec/integration/schema/extending_dsl_spec.rb