Class Spec::Mocks::ArgumentExpectation
In: lib/spec/mocks/argument_expectation.rb
Parent: Object

Methods

Attributes

args  [R] 

Public Class methods

[Source]

     # File lib/spec/mocks/argument_expectation.rb, line 146
146:       def initialize(args)
147:         @args = args
148:         if [:any_args] == args
149:           @expected_params = nil
150:           warn_deprecated(:any_args.inspect, "any_args()")
151:         elsif args.length == 1 && args[0].is_a?(AnyArgsConstraint) then @expected_params = nil
152:         elsif [:no_args] == args
153:           @expected_params = []
154:           warn_deprecated(:no_args.inspect, "no_args()")
155:         elsif args.length == 1 && args[0].is_a?(NoArgsConstraint) then @expected_params = []
156:         else @expected_params = process_arg_constraints(args)
157:         end
158:       end

Public Instance methods

[Source]

     # File lib/spec/mocks/argument_expectation.rb, line 194
194:       def check_args(args)
195:         return true if @expected_params.nil?
196:         return true if @expected_params == args
197:         return constraints_match?(args)
198:       end

[Source]

     # File lib/spec/mocks/argument_expectation.rb, line 200
200:       def constraints_match?(args)
201:         return false if args.length != @expected_params.length
202:         @expected_params.each_index { |i| return false unless @expected_params[i].matches?(args[i]) }
203:         return true
204:       end

[Source]

     # File lib/spec/mocks/argument_expectation.rb, line 170
170:       def convert_constraint(constraint)
171:         if [:anything, :numeric, :boolean, :string].include?(constraint)
172:           case constraint
173:           when :anything
174:             instead = "anything()"
175:           when :boolean
176:             instead = "boolean()"
177:           when :numeric
178:             instead = "an_instance_of(Numeric)"
179:           when :string
180:             instead = "an_instance_of(String)"
181:           end
182:           warn_deprecated(constraint.inspect, instead)
183:           return @@constraint_classes[constraint].new(constraint)
184:         end
185:         return MatcherConstraint.new(constraint) if is_matcher?(constraint)
186:         return RegexpArgConstraint.new(constraint) if constraint.is_a?(Regexp)
187:         return LiteralArgConstraint.new(constraint)
188:       end

[Source]

     # File lib/spec/mocks/argument_expectation.rb, line 190
190:       def is_matcher?(obj)
191:         return obj.respond_to?(:matches?) && obj.respond_to?(:description)
192:       end

[Source]

     # File lib/spec/mocks/argument_expectation.rb, line 160
160:       def process_arg_constraints(constraints)
161:         constraints.collect do |constraint| 
162:           convert_constraint(constraint)
163:         end
164:       end

[Source]

     # File lib/spec/mocks/argument_expectation.rb, line 166
166:       def warn_deprecated(deprecated_method, instead)
167:         Kernel.warn "The #{deprecated_method} constraint is deprecated. Use #{instead} instead."
168:       end

[Validate]