]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/matchers/operator_matcher.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / matchers / operator_matcher.rb
1 module Spec
2   module Matchers
3     class BaseOperatorMatcher
4       attr_reader :generated_description
5       
6       def initialize(target)
7         @target = target
8       end
9
10       def ==(expected)
11         @expected = expected
12         __delegate_method_missing_to_target("==", expected)
13       end
14
15       def ===(expected)
16         @expected = expected
17         __delegate_method_missing_to_target("===", expected)
18       end
19
20       def =~(expected)
21         @expected = expected
22         __delegate_method_missing_to_target("=~", expected)
23       end
24
25       def >(expected)
26         @expected = expected
27         __delegate_method_missing_to_target(">", expected)
28       end
29
30       def >=(expected)
31         @expected = expected
32         __delegate_method_missing_to_target(">=", expected)
33       end
34
35       def <(expected)
36         @expected = expected
37         __delegate_method_missing_to_target("<", expected)
38       end
39
40       def <=(expected)
41         @expected = expected
42         __delegate_method_missing_to_target("<=", expected)
43       end
44
45       def fail_with_message(message)
46         Spec::Expectations.fail_with(message, @expected, @target)
47       end
48
49     end
50
51     class PositiveOperatorMatcher < BaseOperatorMatcher #:nodoc:
52
53       def __delegate_method_missing_to_target(operator, expected)
54         ::Spec::Matchers.generated_description = "should #{operator} #{expected.inspect}"
55         return if @target.send(operator, expected)
56         return fail_with_message("expected: #{expected.inspect},\n     got: #{@target.inspect} (using #{operator})") if ['==','===', '=~'].include?(operator)
57         return fail_with_message("expected: #{operator} #{expected.inspect},\n     got: #{operator.gsub(/./, ' ')} #{@target.inspect}")
58       end
59
60     end
61
62     class NegativeOperatorMatcher < BaseOperatorMatcher #:nodoc:
63
64       def __delegate_method_missing_to_target(operator, expected)
65         ::Spec::Matchers.generated_description = "should not #{operator} #{expected.inspect}"
66         return unless @target.send(operator, expected)
67         return fail_with_message("expected not: #{operator} #{expected.inspect},\n         got: #{operator.gsub(/./, ' ')} #{@target.inspect}")
68       end
69
70     end
71
72   end
73 end