Sha256: 0cc97fca60e442f421dbe41ed1bda69fb12802fce66e045b8832df206b0a97a7

Contents?: true

Size: 602 Bytes

Versions: 7

Compression:

Stored size: 602 Bytes

Contents

RSpec.describe 'Check depending on nth element in an array' do
  subject(:schema) do
    Dry::Validation.Schema do
      required(: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

7 entries across 7 versions & 1 rubygems

Version Path
dry-validation-0.9.5 spec/integration/schema/check_with_nth_el_spec.rb
dry-validation-0.9.4 spec/integration/schema/check_with_nth_el_spec.rb
dry-validation-0.9.3 spec/integration/schema/check_with_nth_el_spec.rb
dry-validation-0.9.2 spec/integration/schema/check_with_nth_el_spec.rb
dry-validation-0.9.1 spec/integration/schema/check_with_nth_el_spec.rb
dry-validation-0.9.0 spec/integration/schema/check_with_nth_el_spec.rb
dry-validation-0.8.0 spec/integration/schema/check_with_nth_el_spec.rb