Class: FlexMock::ExpectationDirector

Inherits:
Object
  • Object
show all
Defined in:
lib/flexmock/expectation_director.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(sym) ⇒ ExpectationDirector

Create an ExpectationDirector for a mock object.



23
24
25
26
27
# File 'lib/flexmock/expectation_director.rb', line 23

def initialize(sym)
  @sym = sym
  @expectations = []
  @expected_order = nil
end

Instance Method Details

#<<(expectation) ⇒ Object

Append an expectation to this director.



46
47
48
# File 'lib/flexmock/expectation_director.rb', line 46

def <<(expectation)
  @expectations << expectation
end

#call(*args) ⇒ Object

Invoke the expectations for a given set of arguments.

First, look for an expectation that matches the arguements 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.



37
38
39
40
41
42
43
# File 'lib/flexmock/expectation_director.rb', line 37

def call(*args)
  exp = @expectations.find { |e| e.match_args(args) && e.eligible? } ||
  @expectations.find { |e| e.match_args(args) }
  FlexMock.check("no matching handler found for " +
  FlexMock.format_args(@sym, args)) { ! exp.nil? }
  exp.verify_call(*args)
end

#mock_verifyObject

Do the post test verification for this directory. Check all the expectations.



52
53
54
55
56
# File 'lib/flexmock/expectation_director.rb', line 52

def mock_verify
  @expectations.each do |exp|
    exp.mock_verify
  end
end