Sha256: 05dc13d4aa3712b73885a5f1aff5b12643fb7cad74983ab8a15443ee9e41a2fa

Contents?: true

Size: 1016 Bytes

Versions: 4

Compression:

Stored size: 1016 Bytes

Contents

require 'dry/validation/predicate'

RSpec.describe Dry::Validation::Predicate do
  describe '#call' do
    it 'returns result of the predicate function' do
      is_empty = Dry::Validation::Predicate.new(:is_empty) { |str| str.empty? }

      expect(is_empty.('')).to be(true)

      expect(is_empty.('filled')).to be(false)
    end
  end

  describe '#negation' do
    it 'returns a negated version of a predicate' do
      is_empty = Dry::Validation::Predicate.new(:is_empty) { |str| str.empty? }
      is_filled = is_empty.negation

      expect(is_filled.('')).to be(false)
      expect(is_filled.('filled')).to be(true)
    end
  end

  describe '#curry' do
    it 'returns curried predicate' do
      min_age = Dry::Validation::Predicate.new(:min_age) { |age, input| input >= age }

      min_age_18 = min_age.curry(18)

      expect(min_age_18.args).to eql([18])

      expect(min_age_18.(18)).to be(true)
      expect(min_age_18.(19)).to be(true)
      expect(min_age_18.(17)).to be(false)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-validation-0.3.1 spec/unit/predicate_spec.rb
dry-validation-0.3.0 spec/unit/predicate_spec.rb
dry-validation-0.2.0 spec/unit/predicate_spec.rb
dry-validation-0.1.0 spec/unit/predicate_spec.rb