lib/caricature/expectation.rb in caricature-0.6.0 vs lib/caricature/expectation.rb in caricature-0.6.1

- old
+ new

@@ -22,15 +22,22 @@ # 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.empty? || (args.first.is_a?(Symbol) and args.first == :any) || (candidates.size == 1 && candidates.first.any_args?) + is_single = (args.first.is_a?(Symbol) and args.first == :any) return candidates.first if is_single - second_pass = candidates.select {|exp| exp.args == args } - second_pass.first + 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 end end # contains the syntax for building up an expectation @@ -129,9 +136,17 @@ def execute(*margs) ags = any_args? ? (margs.empty? ? :any : margs) : args actual_raise *@error_args if has_error_args? return return_value if has_return_value? nil + end + + def to_s + "<Caricature::Expecation, method_name: #{method_name}, args: #{args}, error args: #{error_args}>" + end + + def inspect + to_s end end # Constructs the expecation object. # Used as a boundary between the definition and usage of the expectation \ No newline at end of file