Sha256: 18ac8e5e1edf6e77bb292d2592c664f202125e4c1ff4b2fc419143195137d617

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

RSpec.describe Operations::Each do
  subject(:operation) { Operations::Each.new(is_string) }

  include_context 'predicates'

  let(:is_string) { Rule::Predicate.new(str?) }

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

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

  describe '#to_ast' do
    it 'returns ast' do
      expect(operation.to_ast).to eql([:each, [:predicate, [:str?, [[:input, Undefined]]]]])
    end

    it 'returns result ast' do
      expect(operation.([nil, 12, nil]).to_ast).to eql(
        [:set, [
          [:key, [0, [:predicate, [:str?, [[:input, nil]]]]]],
          [:key, [1, [:predicate, [:str?, [[:input, 12]]]]]],
          [:key, [2, [:predicate, [:str?, [[:input, nil]]]]]]
        ]]
      )
    end

    it 'returns failure result ast' do
      expect(operation.with(id: :tags).([nil, 'red', 12]).to_ast).to eql(
        [:failure, [:tags, [:set, [
          [:key, [0, [:predicate, [:str?, [[:input, nil]]]]]],
          [:key, [2, [:predicate, [:str?, [[:input, 12]]]]]]
        ]]]]
      )
    end
  end

  describe '#to_s' do
    it 'returns string representation' do
      expect(operation.to_s).to eql('each(str?)')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-logic-0.5.0 spec/unit/operations/each_spec.rb
dry-logic-0.4.2 spec/unit/operations/each_spec.rb
dry-logic-0.4.1 spec/unit/operations/each_spec.rb
dry-logic-0.4.0 spec/unit/operations/each_spec.rb