Sha256: 1c25ade028e33df283d3a44f9857f806735df0e6caf3478c6b360cdf09c981c0
Contents?: true
Size: 739 Bytes
Versions: 8
Compression:
Stored size: 739 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, :integer]).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 = :params 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
8 entries across 8 versions & 1 rubygems