Sha256: 4c63a94d9ddf2d72e492cddb0e223f944ebfb250eaa8ae5bdfe38fcbe2c21854

Contents?: true

Size: 1010 Bytes

Versions: 1

Compression:

Stored size: 1010 Bytes

Contents

require 'dry/logic/rule/result'

RSpec.describe Dry::Logic::Rule::Result do
  subject(:rule) { Dry::Logic::Rule::Result.new(:name, min_size?.curry(4)) }

  include_context 'predicates'

  let(:is_str) { Dry::Logic::Rule::Value.new(:name, str?) }
  let(:is_jane) { Dry::Logic::Rule::Result.new(:name, eql?.curry('jane')) }

  describe '#call' do
    it 'returns result of a predicate' do
      expect(rule.(name: is_str.('jane'))).to be_success
      expect(rule.(name: is_str.('jan'))).to be_failure
      expect(rule.(name: is_str.(nil))).to be_failure
    end

    it 'evaluates input for the ast' do
      expect(rule.(name: is_str.('jane')).to_ary).to eql([
        :input, [
          :name, nil, [[:res, [:name, [:predicate, [:min_size?, [4]]]]]]
        ]
      ])
    end
  end

  describe '#and' do
    it 'returns result of a conjunction' do
      expect(rule.and(is_jane).(name: is_str.('jane'))).to be_success
      expect(rule.and(is_jane).(name: is_str.('john'))).to be_failure
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-logic-0.1.1 spec/unit/rule/result_spec.rb