Sha256: b5f17a7cb4b0b930c4a848fa107e9bb9190894607971aa59505be74edc2ceb0a

Contents?: true

Size: 714 Bytes

Versions: 5

Compression:

Stored size: 714 Bytes

Contents

require 'dry/logic/rule'

RSpec.describe Dry::Logic::Rule::Key do
  include_context 'predicates'

  subject(:rule) { Dry::Logic::Rule::Key.new(:name, key?) }

  describe '#call' do
    it 'applies predicate to the value' do
      expect(rule.(name: 'Jane')).to be_success
      expect(rule.({})).to be_failure
    end
  end

  describe '#and' do
    let(:other) { Dry::Logic::Rule::Value.new(:name, str?) }

    it 'returns conjunction rule where value is passed to the right' do
      present_and_string = rule.and(other)

      expect(present_and_string.(name: 'Jane')).to be_success

      expect(present_and_string.({})).to be_failure
      expect(present_and_string.(name: 1)).to be_failure
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dry-logic-0.1.4 spec/unit/rule/key_spec.rb
dry-logic-0.1.3 spec/unit/rule/key_spec.rb
dry-logic-0.1.2 spec/unit/rule/key_spec.rb
dry-logic-0.1.1 spec/unit/rule/key_spec.rb
dry-logic-0.1.0 spec/unit/rule/key_spec.rb