Sha256: a695a5208d1cd0aec27b2cf8ddd4dc8aaba0790748b7c848dc344c638993e148

Contents?: true

Size: 907 Bytes

Versions: 19

Compression:

Stored size: 907 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(UnboundMethod)
    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_a(Method)
      expect(registry[:dis_ok?].()).to be(true)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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