Sha256: 49b1d1feed2f5d5456f505c3cc6b3b64ea2d1088663f15f7165501e128385459

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

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

3 entries across 3 versions & 1 rubygems

Version Path
dry-logic-1.0.0 spec/unit/operations/set_spec.rb
dry-logic-0.6.1 spec/unit/operations/set_spec.rb
dry-logic-0.6.0 spec/unit/operations/set_spec.rb