Sha256: 9451766eff04510d8b68e142e2e4a4336dcbe2217e64b59b64447aa328ba83b1

Contents?: true

Size: 940 Bytes

Versions: 7

Compression:

Stored size: 940 Bytes

Contents

require 'dry/validation/predicate_registry'

RSpec.describe PredicateRegistry do
  subject!(:predicate_registry) { schema_class.registry }

  let(:schema_class) { Class.new(Schema) }
  let(:schema) { schema_class.new }

  before do
    schema_class.class_eval { def dis_ok?; true; end }
  end

  describe '.[]' do
    it 'returns a registry which collects predicate methods' do
      expect(predicate_registry[:dis_ok?]).to be_instance_of(Dry::Logic::Predicate)
    end
  end

  describe '#[]' do
    it 'gives access to built-in predicates' do
      expect(predicate_registry[:filled?].("sutin")).to be(true)
    end
  end

  describe '#bind' do
    it 'binds unbound predicates and return finalized registry' do
      registry = predicate_registry.bind(schema)

      expect(registry).to be_frozen
      expect(registry[:dis_ok?]).to be_instance_of(Dry::Logic::Predicate)
      expect(registry[:dis_ok?].()).to be(true)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dry-validation-0.9.5 spec/unit/predicate_registry_spec.rb
dry-validation-0.9.4 spec/unit/predicate_registry_spec.rb
dry-validation-0.9.3 spec/unit/predicate_registry_spec.rb
dry-validation-0.9.2 spec/unit/predicate_registry_spec.rb
dry-validation-0.9.1 spec/unit/predicate_registry_spec.rb
dry-validation-0.9.0 spec/unit/predicate_registry_spec.rb
dry-validation-0.8.0 spec/unit/predicate_registry_spec.rb