Sha256: 7994e2e2e7b060ec5237344bc613bd26c49156ab782639350e5c1af5315ce49a

Contents?: true

Size: 603 Bytes

Versions: 19

Compression:

Stored size: 603 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(tags: [[: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

19 entries across 19 versions & 1 rubygems

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