Sha256: 8d46273de8d97e8f6408333d9daf34cf9aacd864ab3ee0b3e2a782df7dec994f

Contents?: true

Size: 1.18 KB

Versions: 19

Compression:

Stored size: 1.18 KB

Contents

RSpec.describe Dry::Validation::MessageCompiler, '#visit_failure' do
  include_context :message_compiler

  let(:visitor) { :visit_failure }

  context 'with :int? predicate' do
    let(:node) do
      [:age, [:key, [:age, [:predicate, [:int?, [[:input, '17']]]]]]]
    end

    it 'returns a message for :int? failure with :rule name inferred from key-rule' do
      expect(result.rule).to be(:age)
      expect(result.path).to eql([:age])
      expect(result).to eql('must be an integer')
    end
  end

  context 'with set failure and :int? predicate' do
    let(:node) do
      [:items, [:key, [:items, [:set, [
        [:key, [0, [:predicate, [:int?, [[:input, 'foo']]]]]],
        [:key, [2, [:predicate, [:int?, [[:input, 'bar']]]]]]
      ]]]]]
    end

    it 'returns a message for the first element that failed' do
      expect(result[0].rule).to be(:items)
      expect(result[0].path).to eql([:items, 0])
      expect(result[0]).to eql('must be an integer')
    end

    it 'returns a message for the third element that failed' do
      expect(result[1].rule).to be(:items)
      expect(result[1].path).to eql([:items, 2])
      expect(result[1]).to eql('must be an integer')
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
dry-validation-0.13.3 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.13.2 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.13.1 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.11.2 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.12.3 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.13.0 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.12.2 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.12.1 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.12.0 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.11.1 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.11.0 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.10.7 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.10.6 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.10.5 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.10.4 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.10.3 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.10.2 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.10.1 spec/unit/message_compiler/visit_failure_spec.rb
dry-validation-0.10.0 spec/unit/message_compiler/visit_failure_spec.rb