A collection of expectations with some methods to make it easier to work with them. It allows you to add and find expectations based on certain criteria.
Adds an expectation to this collection. From then on it can be found in the collection.
# File lib/caricature/expectation.rb, line 14 def add_expectation(expectation, mode=:instance) @instance_expectations << expectation unless mode == :class @class_expectations << expectation if mode == :class end
Finds an expectation in the collection. It matches by method_name first. Then it tries to figure out if you care about the arguments. You can say you don’t care by providing 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.
# File lib/caricature/expectation.rb, line 24 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 == :any || (candidates.size == 1 && candidates.first.any_args?) return candidates.first if is_single second_pass = candidates.select {|exp| exp.args == args } second_pass.first end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.