Sha256: 6b0d65f6beca2b327689ae95e49c86f1aa86b2bdc1918cdec513629a2d0265d6

Contents?: true

Size: 1 KB

Versions: 11

Compression:

Stored size: 1 KB

Contents

RSpec.describe Dry::Validation::Result do
  before { Dry::Validation.load_extensions(:monads) }

  let(:schema) { Dry::Validation.Schema { required(:name).filled(:str?, size?: 2..4) } }

  context 'with valid input' do
    let(:input) { { name: 'Jane' } }

    describe '#to_either' do
      it 'returns a Right instance' do
        either = result.to_either

        expect(either).to be_right
        expect(either.value).to eql(name: 'Jane')
      end
    end
  end

  context 'with invalid input' do
    let(:input) { { name: '' } }

    describe '#to_either' do
      it 'returns a Left instance' do
        either = result.to_either

        expect(either).to be_left
        expect(either.value).to eql(name: ['must be filled', 'length must be within 2 - 4'])
      end

      it 'returns full messages' do
        either = result.to_either(full: true)

        expect(either).to be_left
        expect(either.value).to eql(name: ['name must be filled', 'name length must be within 2 - 4'])
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dry-validation-0.11.2 spec/extensions/monads/result_spec.rb
dry-validation-0.11.1 spec/extensions/monads/result_spec.rb
dry-validation-0.11.0 spec/extensions/monads/result_spec.rb
dry-validation-0.10.7 spec/extensions/monads/result_spec.rb
dry-validation-0.10.6 spec/extensions/monads/result_spec.rb
dry-validation-0.10.5 spec/extensions/monads/result_spec.rb
dry-validation-0.10.4 spec/extensions/monads/result_spec.rb
dry-validation-0.10.3 spec/extensions/monads/result_spec.rb
dry-validation-0.10.2 spec/extensions/monads/result_spec.rb
dry-validation-0.10.1 spec/extensions/monads/result_spec.rb
dry-validation-0.10.0 spec/extensions/monads/result_spec.rb