class FlexMock::ExpectationDirector

The expectation director is responsible for routing calls to the correct expectations for a given argument list.

Public Class Methods

new(sym) click to toggle source

Create an ExpectationDirector for a mock object.

# File lib/flexmock/expectation_director.rb, line 23
def initialize(sym)
  @sym = sym
  @expectations = []
  @defaults = []
  @expected_order = nil

Public Instance Methods

<<(expectation) click to toggle source

Append an expectation to this director.

# File lib/flexmock/expectation_director.rb, line 47
def <<(expectation)
  @expectations << expectation
call(args, call_record=nil) click to toggle source

Invoke the expectations for a given set of arguments.

First, look for an expectation that matches the arguments and is eligible to be called. Failing that, look for a expectation that matches the arguments (at this point it will be ineligible, but at least we will get a good failure message). Finally, check for expectations that don't have any argument matching criteria.

# File lib/flexmock/expectation_director.rb, line 38
def call(args, call_record=nil)
  exp = find_expectation(*args)
  call_record.expectation = exp if call_record
    "no matching handler found for " + FlexMock.format_call(@sym, args)) { ! exp.nil? }