module Mocha::ObjectMethods

def stubs(stubbed_methods_vs_return_values)

Other tags:
    See: Mock#stubs -

Other tags:
    Example: Setting up multiple stubbed methods on a non-mock object. -
    Example: Setting up a stubbed methods on a non-mock object. -

Parameters:
  • stubbed_methods_vs_return_values (Hash) -- stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if {#stubs} were called multiple times.
  • method_name (Symbol, String) -- name of stubbed method

Overloads:
  • def stubs(stubbed_methods_vs_return_values)
  • def stubs(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 stubs(stubbed_methods_vs_return_values)
  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(stubbed_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.stubs(method_name, caller)
    expectation.returns(args.shift) unless args.empty?
  end
  expectation
end