Sha256: 20e3869488dff82d9a972f27ca132209343e14097fae52a807da396d1085ef06

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

RSpec.describe Rule::Composite::Disjunction do
  include_context 'predicates'

  subject(:rule) { Rule::Composite::Disjunction.new(left, right) }

  let(:left) { Rule::Value.new(:age, none?) }
  let(:right) { Rule::Value.new(:age, gt?.curry(18)) }

  let(:other) do
    Rule::Value.new(:age, int?) & Rule::Value.new(:age, lt?.curry(14))
  end

  describe '#call' do
    it 'calls left and right' do
      expect(rule.(nil)).to be_success
      expect(rule.(19)).to be_success
      expect(rule.(18)).to be_failure
    end
  end

  describe '#and' do
    it 'creates conjunction with the other' do
      expect(rule.and(other).(nil)).to be_failure
      expect(rule.and(other).(19)).to be_failure
      expect(rule.and(other).(13)).to be_failure
      expect(rule.and(other).(14)).to be_failure
    end
  end

  describe '#or' do
    it 'creates disjunction with the other' do
      expect(rule.or(other).(nil)).to be_success
      expect(rule.or(other).(19)).to be_success
      expect(rule.or(other).(13)).to be_success
      expect(rule.or(other).(14)).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/disjunction_spec.rb
dry-logic-0.1.3 spec/unit/rule/disjunction_spec.rb
dry-logic-0.1.2 spec/unit/rule/disjunction_spec.rb
dry-logic-0.1.1 spec/unit/rule/disjunction_spec.rb
dry-logic-0.1.0 spec/unit/rule/disjunction_spec.rb