1 require File.dirname(__FILE__) + '/test_helper.rb'
3 def false_match(matcher, arg)
4 matcher.matches?(arg).should == false
7 context "A matcher whose condition is Symbol (the class object)" do
9 @matcher = Erlectricity::Matcher.new(nil, Erlectricity::TypeCondition.new(Symbol), nil)
12 specify "should match any symbol" do
13 @matcher.matches?(:foo).should == true
14 @matcher.matches?(:bar).should == true
15 @matcher.matches?(:baz).should == true
18 specify "should not match strings" do
19 @matcher.matches?("foo").should == false
20 @matcher.matches?("bar").should == false
21 @matcher.matches?("baz").should == false
24 specify "should not match a arrays" do
25 @matcher.matches?([:foo]).should == false
26 @matcher.matches?([:foo, :bar]).should == false
27 @matcher.matches?([:foo, :bar, :baz]).should == false
31 context "a matcher whose condition is a symbol" do
33 @matcher = Erlectricity::Matcher.new(nil, Erlectricity::StaticCondition.new(:foo), nil)
36 specify "should match that symbol" do
37 @matcher.matches?(:foo).should == true
40 specify "should not match any other symbol" do
41 @matcher.matches?(:bar).should == false
42 @matcher.matches?(:baz).should == false
46 context "a matcher whose matcher is an array" do
50 specify "should match if all of its children match" do
51 Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:speak), Erlectricity::TypeCondition.new(Object)], nil).matches?([:paste, "haha"]).should == false
53 matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
54 matcher.matches?([:foo, :bar]).should == true
57 specify "should not match any of its children dont match" do
58 matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
59 matcher.matches?([:foo]).should == false
60 matcher.matches?([:foo, :bar, :baz]).should == false
61 matcher.matches?([:fooo, :barr]).should == false
62 matcher.matches?([3, :bar]).should == false
65 specify "should not match if arg isn't an array" do
66 matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
67 matcher.matches?(:foo).should == false