Sha256: a75255b9668d90751acfac76f159282108ddb5773ef627822247915f5e893891
Contents?: true
Size: 1.2 KB
Versions: 4
Compression:
Stored size: 1.2 KB
Contents
RSpec.describe Rule::Check do include_context 'predicates' describe '#call' do context 'with 1-level nesting' do subject(:rule) do Rule::Check.new(eql?.curry(1), name: :compare, keys: [:num]) end it 'applies predicate to args extracted from the input' do expect(rule.(num: 1)).to be_success expect(rule.(num: 2)).to be_failure expect(rule.(num: 1).to_ast).to eql( [:input, [:compare, [ :result, [1, [:check, [:compare, [:predicate, [:eql?, [1]]]]]]]] ] ) end end context 'with 2-levels nesting' do subject(:rule) do Rule::Check.new(eql?, name: :compare, keys: [[:nums, :left], [:nums, :right]]) end it 'applies predicate to args extracted from the input' do expect(rule.(nums: { left: 1, right: 1 })).to be_success expect(rule.(nums: { left: 1, right: 2 })).to be_failure end it 'curries args properly' do result = rule.(nums: { left: 1, right: 2 }) expect(result.to_ast).to eql([ :input, [:compare, [ :result, [1, [:check, [:compare, [:predicate, [:eql?, [2]]]]]]] ] ]) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
dry-logic-0.2.3 | spec/unit/rule/check_spec.rb |
dry-logic-0.2.2 | spec/unit/rule/check_spec.rb |
dry-logic-0.2.1 | spec/unit/rule/check_spec.rb |
dry-logic-0.2.0 | spec/unit/rule/check_spec.rb |