lib/flexmock/argument_matchers.rb in flexmock-0.9.0 vs lib/flexmock/argument_matchers.rb in flexmock-1.0.0.beta.1

- old
+ new

@@ -1,9 +1,9 @@ #!/usr/bin/env ruby #--- -# Copyright 2003-2011 by Jim Weirich (jim@weirichhouse.org). +# Copyright 2003-2012 by Jim Weirich (jim.weirich@gmail.com). # All rights reserved. # # Permission is granted for use, copying, modification, distribution, # and distribution of modified versions of this work as long as the # above copyright notice is included. @@ -52,11 +52,11 @@ "on{...}" end end #################################################################### - # Match only things where the block evaluates to true. + # Match hashes that match all the fields of +hash+. class HashMatcher def initialize(hash) @hash = hash end def ===(target) @@ -66,11 +66,11 @@ "hsh(#{@hash.inspect})" end end #################################################################### - # Match only things where the block evaluates to true. + # Match objects that implement all the methods in +methods+. class DuckMatcher def initialize(methods) @methods = methods end def ===(target) @@ -79,7 +79,20 @@ def inspect "ducktype(#{@methods.map{|m| m.inspect}.join(',')})" end end + #################################################################### + # Match objects that implement all the methods in +methods+. + class OptionalProcMatcher + def initialize + end + def ===(target) + ArgumentMatching.missing?(target) || Proc === target + end + def inspect + "optional_proc" + end + end + OPTIONAL_PROC_MATCHER = OptionalProcMatcher.new end