Parent

Files

Caricature::Expectations

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.

Public Class Methods

new() click to toggle source

initializes a new empty instance of the Expectation collection

    # File lib/caricature/expectation.rb, line 8
 8:     def initialize
 9:       @instance_expectations = []
10:       @class_expectations = []
11:     end

Public Instance Methods

add_expectation(expectation, mode=:instance) click to toggle source

Adds an expectation to this collection. From then on it can be found in the collection.

    # File lib/caricature/expectation.rb, line 14
14:     def add_expectation(expectation, mode=:instance)
15:       @instance_expectations << expectation unless mode == :class
16:       @class_expectations << expectation if mode == :class
17:     end
find(method_name, mode=:instance, *args) click to toggle source

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
24:     def find(method_name, mode=:instance, *args)
25:       expectations = mode == :class ? @class_expectations : @instance_expectations
26: 
27:       candidates = expectations.select { |exp| exp.method_name.to_s.underscore =~ /#{method_name}|#{method_name.to_s.underscore}/ }
28:       with_arguments_candidates = candidates.select { |exp| exp.args == args }
29:       
30:       with_arguments_candidates.first || candidates.select { |exp| exp.any_args?  }.first
31:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.