Sha256: ed8983f03123174a283f947b20056290b00a23d10e1e4cb9ed232ddcf4db4d55

Contents?: true

Size: 824 Bytes

Versions: 3

Compression:

Stored size: 824 Bytes

Contents

RSpec.describe Dry::Validation::Schema, 'defining schema using dry types' do
  subject(:schema) do
    Dry::Validation.Schema do
      key(:email).required(Email)
      key(:age).maybe(Age)
    end
  end

  before do
    Email = Dry::Types['strict.string']
    Age = Dry::Types['strict.int'].constrained(gt: 18)
  end

  after do
    Object.send(:remove_const, :Email)
    Object.send(:remove_const, :Age)
  end

  it 'passes when input is valid' do
    expect(schema.(email: 'jane@doe', age: 19)).to be_success
    expect(schema.(email: 'jane@doe', age: nil)).to be_success
  end

  it 'fails when input is not valid' do
    expect(schema.(email: '', age: 19)).to_not be_success
    expect(schema.(email: 'jane@doe', age: 17)).to_not be_success
    expect(schema.(email: 'jane@doe', age: '19')).to_not be_success
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-validation-0.7.2 spec/integration/schema/using_types_spec.rb
dry-validation-0.7.1 spec/integration/schema/using_types_spec.rb
dry-validation-0.7.0 spec/integration/schema/using_types_spec.rb