class FlexMock::ExpectationDirector
The expectation director is responsible for routing calls to the correct expectations for a given argument list.
Public Class Methods
Source
# File lib/flexmock/expectation_director.rb, line 22 def initialize(sym) @sym = sym @expectations = [] @defaults = [] @expected_order = nil end
Create an ExpectationDirector
for a mock object.
Public Instance Methods
Source
# File lib/flexmock/expectation_director.rb, line 51 def <<(expectation) @expectations << expectation end
Append an expectation to this director.
Source
# File lib/flexmock/expectation_director.rb, line 37 def call(args, kw, block, call_record=nil) exp = find_expectation(args, kw, block) call_record.expectation = exp if call_record FlexMock.check( proc { "no matching handler found for " + FlexMock.format_call(@sym, args, kw) + "\nDefined expectations:\n " + @expectations.map(&:description).join("\n ") } ) { !exp.nil? } returned_value = exp.verify_call(args, kw, block) returned_value end
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.
Private Instance Methods
Source
# File lib/flexmock/expectation_director.rb, line 86 def find_expectation_in(expectations, args, kw, block) expectations.find { |e| e.match_args(args, kw, block) && e.eligible? } || expectations.find { |e| e.match_args(args, kw, block) } end