lib/muack/satisfying.rb in muack-1.3.1 vs lib/muack/satisfying.rb in muack-1.3.2

- old
+ new

@@ -114,10 +114,11 @@ api_args.all?{ |msg| actual_arg.respond_to?(msg) } end end class Where < Satisfying + None = Object.new def initialize spec super([spec]) end def match actual_arg, spec=api_args.first @@ -132,30 +133,38 @@ end private def match_hash actual_arg, spec (spec.keys | actual_arg.keys).all? do |key| - match_value(actual_arg[key], spec[key]) + match_value(actual_arg, spec, key) end end def match_array actual_arg, spec spec.zip(actual_arg).all? do |(ev, av)| match_value(av, ev) end end - def match_value av, ev - case ev + def match_value av, ev, key=None + if key == None + a, e = av, ev + elsif av.key?(key) && ev.key?(key) + a, e = av[key], ev[key] + else + return false + end + + case e when Satisfying - ev.match(av) + e.match(a) when Hash - av.kind_of?(Hash) && match_hash(av, ev) + a.kind_of?(Hash) && match_hash(a, e) when Array - av.kind_of?(Array) && match_array(av, ev) + a.kind_of?(Array) && match_array(a, e) else - ev == av + e == a end end end class Having < Where @@ -164,11 +173,11 @@ end private def match_hash actual_arg, subset subset.each_key.all? do |key| - match_value(actual_arg[key], subset[key]) + match_value(actual_arg, subset, key) end end end class Allowing < Where @@ -177,10 +186,10 @@ end private def match_hash actual_arg, superset actual_arg.each_key.all? do |key| - match_value(actual_arg[key], superset[key]) + match_value(actual_arg, superset, key) end end end end