Sha256: 8976f2d88c949b02bed727e6e022d213734438fae1ab128ea3edd0b5f7573b7c

Contents?: true

Size: 845 Bytes

Versions: 3

Compression:

Stored size: 845 Bytes

Contents

require 'dry/logic/rule'

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

  subject(:address_rule) do
    Dry::Logic::Rule::Each.new(is_string)
  end

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

  describe '#call' do
    it 'applies its rules to all elements in the input' do
      expect(address_rule.(['Address'])).to be_success

      expect(address_rule.([nil, 'Address'])).to be_failure
      expect(address_rule.([:Address, 'Address'])).to be_failure
    end

    it 'returns result ast' do
      expect(address_rule.([nil, nil]).to_ast).to eql([
        :result, [[nil, nil], [
          :each, [
            [:el, [0, [:result, [nil, [:val, [:predicate, [:str?, []]]]]]]],
            [:el, [1, [:result, [nil, [:val, [:predicate, [:str?, []]]]]]]]
          ]
        ]]
      ])
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-logic-0.2.3 spec/unit/rule/each_spec.rb
dry-logic-0.2.2 spec/unit/rule/each_spec.rb
dry-logic-0.2.1 spec/unit/rule/each_spec.rb