lib/caricature/expectation.rb in caricature-0.6.1 vs lib/caricature/expectation.rb in caricature-0.6.3
- old
+ new
@@ -21,22 +21,14 @@
# the symbol +:any+ as first argument to this method. When you don't care the first match is being returned
# When you specify arguments other than +:any+ it will try to match the specified arguments in addition
# to the method name. It will then also return the first result it can find.
def find(method_name, mode=:instance, *args)
expectations = mode == :class ? @class_expectations : @instance_expectations
- candidates = expectations.select { |exp| exp.method_name.to_s.to_sym == method_name.to_s.to_sym }
- is_single = (args.first.is_a?(Symbol) and args.first == :any)
- return candidates.first if is_single
- second_pass = candidates.select do |exp|
- result = false
- exp.args.each_with_index do |item, idx|
- result = true if args[idx] == item
- end
- result
- end
- return second_pass.first unless second_pass.empty?
- candidates.select { |exp| exp.any_args? }.first
+ candidates = expectations.select { |exp| exp.method_name.to_s.to_sym == method_name.to_s.to_sym }
+ with_arguments_candidates = candidates.select { |exp| exp.args == args }
+
+ with_arguments_candidates.first || candidates.select { |exp| exp.any_args? }.first
end
end
# contains the syntax for building up an expectation
\ No newline at end of file