Sha256: 7a3dfd559bd0d99f7384f415acd57a534b3524a0399d9900fb437d27e5fdf0ed

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 KB

Contents

RSpec.describe Result do
  include_context 'predicates'

  describe '#to_s' do
    shared_examples_for 'string representation' do
      it 'returns string representation' do
        expect(rule.(input).to_s).to eql(output)
      end
    end

    context 'with a predicate' do
      let(:rule) { Rule::Predicate.build(gt?, args: [18]) }
      let(:input) { 17 }
      let(:output) { 'gt?(18, 17)' }

      it_behaves_like 'string representation'
    end

    context 'with AND operation' do
      let(:rule) { Rule::Predicate.build(array?).and(Rule::Predicate.build(empty?)) }
      let(:input) { '' }
      let(:output) { 'array?("") AND empty?("")' }

      it_behaves_like 'string representation'
    end

    context 'with OR operation' do
      let(:rule) { Rule::Predicate.build(array?).or(Rule::Predicate.build(empty?)) }
      let(:input) { 123 }
      let(:output) { 'array?(123) OR empty?(123)' }

      it_behaves_like 'string representation'
    end

    context 'with XOR operation' do
      let(:rule) { Rule::Predicate.build(array?).xor(Rule::Predicate.build(empty?)) }
      let(:input) { [] }
      let(:output) { 'array?([]) XOR empty?([])' }

      it_behaves_like 'string representation'
    end

    context 'with THEN operation' do
      let(:rule) { Rule::Predicate.build(array?).then(Rule::Predicate.build(empty?)) }
      let(:input) { [1, 2, 3] }
      let(:output) { 'empty?([1, 2, 3])' }

      it_behaves_like 'string representation'
    end

    context 'with NOT operation' do
      let(:rule) { Operations::Negation.new(Rule::Predicate.build(array?)) }
      let(:input) { 'foo' }
      let(:output) { 'not(array?("foo"))' }

      it_behaves_like 'string representation'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-logic-1.0.0 spec/integration/result_spec.rb
dry-logic-0.6.1 spec/integration/result_spec.rb
dry-logic-0.6.0 spec/integration/result_spec.rb