Sha256: 988aac016954eff5bcad069f0ddfb5e3cfec6d0020bb41b21e2abe786728a581
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
RSpec.describe Rule::Predicate do subject(:rule) { Rule::Predicate.build(predicate) } let(:predicate) { str? } include_context 'predicates' it_behaves_like Rule describe '#name' do it 'returns predicate identifier' do expect(rule.name).to be(:str?) end end describe '#to_ast' do context 'without a result' do it 'returns rule ast' do expect(rule.to_ast).to eql([:predicate, [:str?, [[:input, Undefined]]]]) end it 'returns :failure with an id' do email = rule.with(id: :email) expect(email.(11).to_ast).to eql([:failure, [:email, [:predicate, [:str?, [[:input, 11]]]]]]) end end context 'with a result' do it 'returns success' do expect(rule.('foo')).to be_success end it 'returns failure ast' do expect(rule.(5).to_ast).to eql([:predicate, [:str?, [[:input, 5]]]]) end end context 'with a zero-arity predicate' do let(:predicate) { Module.new { def self.test?; true; end }.method(:test?) } it 'returns ast' do expect(rule.to_ast).to eql([:predicate, [:test?, []]]) end end end describe '#to_s' do it 'returns string representation' do expect(rule.curry('foo').to_s).to eql('str?("foo")') end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dry-logic-1.0.0 | spec/unit/rule/predicate_spec.rb |
dry-logic-0.6.1 | spec/unit/rule/predicate_spec.rb |
dry-logic-0.6.0 | spec/unit/rule/predicate_spec.rb |