Sha256: 1e11b2cae344ee89eb2e343c1f4593a201b2e3f314e64d5e1dadf697998951cb

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

RSpec.describe Operations::Set do
  subject(:operation) { Operations::Set.new(is_int, gt_18) }

  include_context 'predicates'

  let(:is_int) { Rule::Predicate.build(int?) }
  let(:gt_18) { Rule::Predicate.build(gt?, args: [18]) }

  describe '#call' do
    it 'applies all its rules to the input' do
      expect(operation.(19)).to be_success
      expect(operation.(17)).to be_failure
    end
  end

  describe '#to_ast' do
    it 'returns ast' do
      expect(operation.to_ast).to eql(
        [:set, [[:predicate, [:int?, [[:input, Undefined]]]], [:predicate, [:gt?, [[:num, 18], [:input, Undefined]]]]]]
      )
    end

    it 'returns result ast' do
      expect(operation.(17).to_ast).to eql(
        [:set, [[:predicate, [:gt?, [[:num, 18], [:input, 17]]]]]]
      )
    end

    it 'returns result ast with an :id' do
      expect(operation.with(id: :age).(17).to_ast).to eql(
        [:failure, [:age, [:set, [[:predicate, [:gt?, [[:num, 18], [:input, 17]]]]]]]]
      )
    end
  end

  describe '#to_s' do
    it 'returns string representation' do
      expect(operation.to_s).to eql('set(int?, gt?(18))')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-logic-1.0.5 spec/unit/operations/set_spec.rb
dry-logic-1.0.4 spec/unit/operations/set_spec.rb
dry-logic-1.0.3 spec/unit/operations/set_spec.rb
dry-logic-1.0.2 spec/unit/operations/set_spec.rb