lib/bogus/any_args.rb in bogus-0.1.0 vs lib/bogus/any_args.rb in bogus-0.1.1
- old
+ new
@@ -1,7 +1,36 @@
module Bogus
- module AnyArgs
- def self.inspect
- "any_args"
+ class WithArguments
+ attr_reader :predicate
+
+ def initialize(&predicate)
+ @predicate = predicate
end
+
+ def matches?(args)
+ predicate.call(*args)
+ end
+
+ def self.matches?(opts = {})
+ stubbed = opts.fetch(:stubbed)
+ recorded = opts.fetch(:recorded)
+ return false unless with_matcher?(stubbed)
+ return extract(stubbed).matches?(recorded)
+ end
+
+ def self.with_matcher?(args)
+ args.first.is_a?(WithArguments)
+ end
+
+ private
+
+ def self.extract(args)
+ args.first
+ end
+ end
+
+ AnyArgs = WithArguments.new{ true }
+
+ def AnyArgs.inspect
+ "any_args"
end
end