@@ -10,98 +10,52 @@ class Module
1010 include MSpecMatchers
1111end
1212
13- class SpecPositiveOperatorMatcher
13+ class SpecPositiveOperatorMatcher < BasicObject
1414 def initialize ( actual )
1515 @actual = actual
1616 end
1717
1818 def ==( expected )
19- unless @actual == expected
20- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
21- "to equal #{ MSpec . format ( expected ) } " )
22- end
19+ method_missing ( :== , expected )
2320 end
2421
25- def <( expected )
26- unless @actual < expected
27- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
28- "to be less than #{ MSpec . format ( expected ) } " )
29- end
30- end
31-
32- def <=( expected )
33- unless @actual <= expected
34- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
35- "to be less than or equal to #{ MSpec . format ( expected ) } " )
36- end
22+ def !=( expected )
23+ method_missing ( :!= , expected )
3724 end
3825
39- def >( expected )
40- unless @actual > expected
41- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
42- "to be greater than #{ MSpec . format ( expected ) } " )
43- end
44- end
45-
46- def >=( expected )
47- unless @actual >= expected
48- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
49- "to be greater than or equal to #{ MSpec . format ( expected ) } " )
50- end
26+ def equal? ( expected )
27+ method_missing ( :equal? , expected )
5128 end
5229
53- def =~ ( expected )
54- unless @actual =~ expected
55- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
56- "to match #{ MSpec . format ( expected ) } " )
30+ def method_missing ( name , * args , & block )
31+ result = @actual . __send__ ( name , * args , & block )
32+ unless result
33+ :: SpecExpectation . fail_predicate ( @actual , name , args , block , result , "to be truthy " )
5734 end
5835 end
5936end
6037
61- class SpecNegativeOperatorMatcher
38+ class SpecNegativeOperatorMatcher < BasicObject
6239 def initialize ( actual )
6340 @actual = actual
6441 end
6542
6643 def ==( expected )
67- if @actual == expected
68- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
69- "not to equal #{ MSpec . format ( expected ) } " )
70- end
44+ method_missing ( :== , expected )
7145 end
7246
73- def <( expected )
74- if @actual < expected
75- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
76- "not to be less than #{ MSpec . format ( expected ) } " )
77- end
78- end
79-
80- def <=( expected )
81- if @actual <= expected
82- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
83- "not to be less than or equal to #{ MSpec . format ( expected ) } " )
84- end
47+ def !=( expected )
48+ method_missing ( :!= , expected )
8549 end
8650
87- def >( expected )
88- if @actual > expected
89- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
90- "not to be greater than #{ MSpec . format ( expected ) } " )
91- end
92- end
93-
94- def >=( expected )
95- if @actual >= expected
96- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
97- "not to be greater than or equal to #{ MSpec . format ( expected ) } " )
98- end
51+ def equal? ( expected )
52+ method_missing ( :equal? , expected )
9953 end
10054
101- def =~ ( expected )
102- if @actual =~ expected
103- SpecExpectation . fail_with ( "Expected #{ MSpec . format ( @actual ) } " ,
104- "not to match #{ MSpec . format ( expected ) } ")
55+ def method_missing ( name , * args , & block )
56+ result = @actual . __send__ ( name , * args , & block )
57+ if result
58+ :: SpecExpectation . fail_predicate ( @actual , name , args , block , result , " to be falsy ")
10559 end
10660 end
10761end
0 commit comments