module Mocha::ObjectMethods
def expects(expected_methods_vs_return_values)
- See: Mock#expects -
Other tags:
- Example: Setting up multiple expectations on a non-mock object. -
Example: Setting up an expectation on a non-mock object. -
Parameters:
-
expected_methods_vs_return_values
(Hash
) -- expected method name symbols as keys and corresponding return values as values - these expectations are setup as if {#expects} were called multiple times. -
method_name
(Symbol, String
) -- name of expected method
Overloads:
-
def expects(expected_methods_vs_return_values)
-
def expects(method_name)
Raises:
-
(StubbingError)
- if attempting to stub method which is not allowed.
Returns:
-
(Expectation)
- last-built expectation which can be further modified by methods on {Expectation}.
def expects(expected_methods_vs_return_values) if expected_methods_vs_return_values.to_s =~ /the[^a-z]*spanish[^a-z]*inquisition/i raise ExpectationErrorFactory.build('NOBODY EXPECTS THE SPANISH INQUISITION!') end if frozen? raise StubbingError.new("can't stub method on frozen object: #{mocha_inspect}", caller) end expectation = nil mockery = Mocha::Mockery.instance iterator = ArgumentIterator.new(expected_methods_vs_return_values) iterator.each do |*args| method_name = args.shift mockery.on_stubbing(self, method_name) method = stubba_method.new(stubba_object, method_name) mockery.stubba.stub(method) expectation = mocha.expects(method_name, caller) expectation.returns(args.shift) unless args.empty? end expectation end