Sha256: 76109284bf03b3cc3e3d5ba5e1e9c7b88c8fd69b5e4628b7aab188897b112d6b

Contents?: true

Size: 597 Bytes

Versions: 5

Compression:

Stored size: 597 Bytes

Contents

RSpec.describe 'Check depending on nth element in an array' do
  subject(:schema) do
    Dry::Validation.Schema do
      key(:tags).each(:str?)

      rule(red: [[:tags, 0]]) do |value|
        value.eql?('red')
      end
    end
  end

  it 'skips check when dependency failed' do
    expect(schema.(tags: 'oops')).to be_failure
  end

  it 'passes when check passes' do
    expect(schema.(tags: %w(red green blue))).to be_success
  end

  it 'fails when check fails' do
    expect(schema.(tags: %w(blue green red)).messages).to eql(
      tags: { 0 => ["must be equal to red"] }
    )
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dry-validation-0.7.4 spec/integration/schema/check_with_nth_el_spec.rb
dry-validation-0.7.3 spec/integration/schema/check_with_nth_el_spec.rb
dry-validation-0.7.2 spec/integration/schema/check_with_nth_el_spec.rb
dry-validation-0.7.1 spec/integration/schema/check_with_nth_el_spec.rb
dry-validation-0.7.0 spec/integration/schema/check_with_nth_el_spec.rb