module Mocha::API

def self.extended(mod)

Other tags:
    Private: -
def self.extended(mod)
  included(mod)
end

def self.included(_mod)

Other tags:
    Private: -
def self.included(_mod)
  Object.send(:include, Mocha::ObjectMethods)
  Class.send(:include, Mocha::ClassMethods)
end

def mock(*arguments)

Other tags:
    Example: Using expected_methods_vs_return_values Hash to setup expectations. -

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 {Mock#expects} were called multiple times.
  • name (String, Symbol) -- identifies mock object in error messages.
  • expected_methods_vs_return_values (Hash) -- expected method name symbols as keys and corresponding return values as values - these expectations are setup as if {Mock#expects} were called multiple times.
  • name (String, Symbol) -- identifies mock object in error messages.

Overloads:
  • def mock(name, expected_methods_vs_return_values = {})
  • def mock(expected_methods_vs_return_values = {})
  • def mock(name)

Returns:
  • (Mock) - a new mock object
def mock(*arguments)
  name = arguments.shift.to_s if arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
  expectations = arguments.shift || {}
  mock = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
  mock.expects(expectations)
  mock
end

def sequence(name)

Other tags:
    Example: Ensure methods on egg are invoked in the correct order using a block. -
    Example: Ensure methods across multiple objects are invoked in correct order. -
    Example: Ensure methods on egg are invoked in correct order. -

Other tags:
    See: Expectation#in_sequence -

Returns:
  • (Sequence) - a new sequence

Other tags:
    Yield: - optional block within which expectations should be constrained by the sequence

Parameters:
  • name (String) -- name of sequence
def sequence(name)
  Sequence.new(name).tap do |seq|
    Mockery.instance.sequences.push(seq)
    begin
      yield if block_given?
    ensure
      Mockery.instance.sequences.pop
    end
  end
end

def states(name)

Other tags:
    Example: Constrain expected invocations to occur in particular states. -

Other tags:
    See: StateMachine -
    See: Expectation#when -
    See: Expectation#then -

Returns:
  • (StateMachine) - a new state machine

Parameters:
  • name (String) -- name of state machine
def states(name)
  Mockery.instance.new_state_machine(name)
end

def stub(*arguments)

Other tags:
    Example: Using stubbed_methods_vs_return_values Hash to setup stubbed methods. -

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 {Mock#stubs} were called multiple times.
  • name (String, Symbol) -- identifies mock object in error messages.
  • 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 {Mock#stubs} were called multiple times.
  • name (String, Symbol) -- identifies mock object in error messages.

Overloads:
  • def stub(name, stubbed_methods_vs_return_values = {})
  • def stub(stubbed_methods_vs_return_values = {})
  • def stub(name)

Returns:
  • (Mock) - a new mock object
def stub(*arguments)
  name = arguments.shift.to_s if arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
  expectations = arguments.shift || {}
  stub = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
  stub.stubs(expectations)
  stub
end

def stub_everything(*arguments)

Other tags:
    Example: Ignore invocations of irrelevant methods. -

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 {Mock#stubs} were called multiple times.
  • name (String, Symbol) -- identifies mock object in error messages.
  • 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 {Mock#stubs} were called multiple times.
  • name (String, Symbol) -- identifies mock object in error messages.

Overloads:
  • def stub_everything(name, stubbed_methods_vs_return_values = {})
  • def stub_everything(stubbed_methods_vs_return_values = {})
  • def stub_everything(name)

Returns:
  • (Mock) - a new mock object
def stub_everything(*arguments)
  name = arguments.shift if arguments.first.is_a?(String) || arguments.first.is_a?(Symbol)
  expectations = arguments.shift || {}
  stub = name ? Mockery.instance.named_mock(name) : Mockery.instance.unnamed_mock
  stub.stub_everything
  stub.stubs(expectations)
  stub
end