Sha256: e8e75bb72a5fa1eaa1738191d692d8cfecfa67c68412628e827fec2699d49aa4

Contents?: true

Size: 792 Bytes

Versions: 1

Compression:

Stored size: 792 Bytes

Contents

require 'dry/logic/rule'

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

  subject(:rule) do
    Dry::Logic::Rule::Set.new([is_string, min_size.curry(6)])
  end

  let(:is_string) { Dry::Logic::Rule::Value.new(str?) }
  let(:min_size) { Dry::Logic::Rule::Value.new(min_size?) }

  describe '#call' do
    it 'applies its rules to the input' do
      expect(rule.('Address')).to be_success
      expect(rule.('Addr')).to be_failure
    end
  end

  describe '#to_ast' do
    it 'returns an array representation' do
      expect(rule.to_ast).to eql([
        :set, [
          [:val, [:predicate, [:str?, [[:input, Predicate::Undefined]]]]],
          [:val, [:predicate, [:min_size?, [[:num, 6], [:input, Predicate::Undefined]]]]]
        ]
      ])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-logic-0.3.0 spec/unit/rule/set_spec.rb