aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/nogaim.h
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/nogaim.h')
0 files changed, 0 insertions, 0 deletions
Unnamed repository; edit this file 'description' to name the repository.MimesBrønn
aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/plugins/rspec/lib/spec/matchers/be.rb
blob: 0eb1629a64e53dc7ef6707a6a8a3216b26c5e729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
module Spec
  module Matchers
    
    class Be #:nodoc:
      def initialize(*args)
        @expected = parse_expected(args.shift)
        @args = args
        @comparison = ""
      end
      
      def matches?(actual)
        @actual = actual
        return true if match_or_compare unless handling_predicate?
        if handling_predicate?
          begin
            return @result = actual.__send__(predicate, *@args)
          rescue => predicate_error
            # This clause should be empty, but rcov will not report it as covered
            # unless something (anything) is executed within the clause
            rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
          end

          # This supports should_exist > target.exists? in the old world.
          # We should consider deprecating that ability as in the new world
          # you can't write "should exist" unless you have your own custom matcher.
          begin
            return @result = actual.__send__(present_tense_predicate, *@args)
          rescue
            raise predicate_error
          end
        end
        return false
      end
      
      def failure_message
        return "expected #{@comparison}#{expected}, got #{@actual.inspect}" unless handling_predicate?
        return "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
      end
      
      def negative_failure_message
        return "expected not #{expected}, got #{@actual.inspect}" unless handling_predicate?
        return "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
      end
      
      def expected
        return true if @expected == :true
        return false if @expected == :false
        return "nil" if @expected == :nil
        return @expected.inspect
      end
      
      def match_or_compare
        return @actual == true if @expected == :true
        return @actual == false if @expected == :false
        return @actual.nil? if @expected == :nil
        return @actual < @expected if @less_than
        return @actual <= @expected if @less_than_or_equal
        return @actual >= @expected if @greater_than_or_equal
        return @actual > @expected if @greater_than
        return @actual == @expected if @double_equal
        return @actual === @expected if @triple_equal
        return @actual.equal?(@expected)
      end
      
      def ==(expected)
        @double_equal = true
        @comparison = "== "
        @expected = expected
        self
      end

      def ===(expected)
        @triple_equal = true
        @comparison = "=== "
        @expected = expected
        self
      end

      def <(expected)
        @less_than = true
        @comparison = "< "
        @expected = expected
        self
      end

      def <=(expected)
        @less_than_or_equal = true
        @comparison = "<= "
        @expected = expected
        self
      end

      def >=(expected)
        @greater_than_or_equal = true
        @comparison = ">= "
        @expected = expected
        self
      end

      def >(expected)
        @greater_than = true
        @comparison = "> "
        @expected = expected
        self
      end
      
      def description
        "#{prefix_to_sentence}#{comparison}#{expected_to_sentence}#{args_to_sentence}"
      end

      private
        def parse_expected(expected)
          if Symbol === expected
            @handling_predicate = true
            ["be_an_","be_a_","be_"].each do |@prefix|
              return "#{expected.to_s.sub(@prefix,"")}".to_sym if expected.starts_with?(@prefix)
            end
          end
          @prefix = "be "
          return expected
        end
        
        def handling_predicate?
          return false if [:true, :false, :nil].include?(@expected)
          return @handling_predicate
        end

        def predicate
          "#{@expected.to_s}?".to_sym
        end
        
        def present_tense_predicate
          "#{@expected.to_s}s?".to_sym
        end
        
        def args_to_s
          return "" if @args.empty?
          inspected_args = @args.collect{|a| a.inspect}
          return "(#{inspected_args.join(', ')})"
        end
        
        def comparison
          @comparison
        end
        
        def expected_to_sentence
          split_words(@expected)
        end
        
        def prefix_to_sentence
          split_words(@prefix)
        end

        def split_words(sym)
          sym.to_s.gsub(/_/,' ')
        end

        def args_to_sentence
          case @args.length
            when 0
              ""
            when 1
              " #{@args[0]}"
            else
              " #{@args[0...-1].join(', ')} and #{@args[-1]}"
          end
        end
        
    end
 
    # :call-seq:
    #   should be_true
    #   should be_false
    #   should be_nil
    #   should be_arbitrary_predicate(*args)
    #   should_not be_nil
    #   should_not be_arbitrary_predicate(*args)
    #
    # Given true, false, or nil, will pass if actual is
    # true, false or nil (respectively).
    #
    # Predicates are any Ruby method that ends in a "?" and returns true or false.
    # Given be_ followed by arbitrary_predicate (without the "?"), RSpec will match
    # convert that into a query against the target object.
    #
    # The arbitrary_predicate feature will handle any predicate
    # prefixed with "be_an_" (e.g. be_an_instance_of), "be_a_" (e.g. be_a_kind_of)
    # or "be_" (e.g. be_empty), letting you choose the prefix that best suits the predicate.
    #
    # == Examples 
    #
    #   target.should be_true
    #   target.should be_false
    #   target.should be_nil
    #   target.should_not be_nil
    #
    #   collection.should be_empty #passes if target.empty?
    #   "this string".should be_an_intance_of(String)
    #
    #   target.should_not be_empty #passes unless target.empty?
    #   target.should_not be_old_enough(16) #passes unless target.old_enough?(16)
    def be(*args)
      Matchers::Be.new(*args)
    end
  end
end