spec/integration/optional_keys_spec.rb in dry-validation-0.6.0 vs spec/integration/optional_keys_spec.rb in dry-validation-0.7.0

- old
+ new

@@ -1,30 +1,28 @@ RSpec.describe Dry::Validation::Schema do - subject(:validation) { schema.new } - describe 'defining schema with optional keys' do - let(:schema) do - Class.new(Dry::Validation::Schema) do + subject(:schema) do + Dry::Validation.Schema do optional(:email) { |email| email.filled? } - key(:address) do |address| - address.key(:city, &:filled?) - address.key(:street, &:filled?) + key(:address) do + key(:city, &:filled?) + key(:street, &:filled?) - address.optional(:phone_number) do |phone_number| - phone_number.none? | phone_number.str? + optional(:phone_number) do + none? | str? end end end end describe '#call' do it 'skips rules when key is not present' do - expect(validation.(address: { city: 'NYC', street: 'Street 1/2' })).to be_empty + expect(schema.(address: { city: 'NYC', street: 'Street 1/2' })).to be_success end it 'applies rules when key is present' do - expect(validation.(email: '')).to_not be_empty + expect(schema.(email: '')).to_not be_success end end end end