1 # Copyright 2007-2014 Greg Hurrell. All rights reserved.
2 # Licensed under the terms of the BSD 2-clause license.
6 describe Walrat::Predicate do
7 it 'raises an ArgumentError if initialized with nil' do
9 Walrat::Predicate.new nil
10 end.to raise_error(ArgumentError, /nil parseable/)
13 it 'complains if sent "parse" message' do
14 # Predicate abstract superclass, "parse" is the responsibility of the
17 Walrat::Predicate.new('foo').parse 'bar'
18 end.to raise_error(NotImplementedError)
21 it 'should be able to compare predicates for equality' do
22 Walrat::Predicate.new('foo').should eql(Walrat::Predicate.new('foo'))
23 Walrat::Predicate.new('foo').should_not eql(Walrat::Predicate.new('bar'))
26 it '"and" and "not" predicates should yield different hashes even if initialized with the same "parseable"' do
27 parseable = 'foo'.to_parseable
28 p1 = Walrat::Predicate.new(parseable)
29 p2 = Walrat::AndPredicate.new(parseable)
30 p3 = Walrat::NotPredicate.new(parseable)
32 p1.hash.should_not == p2.hash
33 p2.hash.should_not == p3.hash
34 p3.hash.should_not == p1.hash