Parent

Methods

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
    def initialize
      @inner = []
    end

Public Instance Methods

<<(expectation) 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 13
    def <<(expectation)
      @inner << expectation
    end
find(method_name, *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 22
    def find(method_name, *args)
      candidates = @inner.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.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.