Module: Mocha — Mocha 3.1.0

# Module: Mocha

Defined in:
  lib/mocha.rb,
  lib/mocha/api.rb,
  lib/mocha/hooks.rb,
  lib/mocha/mock.rb,
  lib/mocha/expectation.rb,
  lib/mocha/object_methods.rb,
  lib/mocha/class_methods.rb,
  lib/mocha/parameter_matchers.rb,
  lib/mocha/parameter_matchers/not.rb,
  lib/mocha/parameter_matchers/is_a.rb,
  lib/mocha/parameter_matchers/all_of.rb,
  lib/mocha/parameter_matchers/any_of.rb,
  lib/mocha/parameter_matchers/equals.rb,
  lib/mocha/parameter_matchers/has_key.rb,
  lib/mocha/parameter_matchers/kind_of.rb,
  lib/mocha/parameter_matchers/anything.rb,
  lib/mocha/parameter_matchers/has_keys.rb,
  lib/mocha/parameter_matchers/includes.rb,
  lib/mocha/parameter_matchers/has_entry.rb,
  lib/mocha/parameter_matchers/has_value.rb,
  lib/mocha/parameter_matchers/optionally.rb,
  lib/mocha/parameter_matchers/has_entries.rb,
  lib/mocha/parameter_matchers/instance_of.rb,
  lib/mocha/parameter_matchers/base_methods.rb,
  lib/mocha/parameter_matchers/responds_with.rb,
  lib/mocha/parameter_matchers/any_parameters.rb,
  lib/mocha/parameter_matchers/equivalent_uri.rb,
  lib/mocha/parameter_matchers/regexp_matches.rb,
  lib/mocha/parameter_matchers/yaml_equivalent.rb,
  lib/mocha/parameter_matchers/instance_methods.rb,
  lib/mocha/parameter_matchers/positional_or_keyword_hash.rb,
  lib/mocha/state_machine.rb,
  lib/mocha/sequence.rb,
  lib/mocha/configuration.rb,
  lib/mocha/expectation_error_factory.rb,
  lib/mocha/expectation_error.rb,
  lib/mocha/stubbing_error.rb,
  lib/mocha/integration.rb,
  lib/mocha/integration/test_unit/adapter.rb,
  lib/mocha/integration/minitest/adapter.rb

## Overview

Mocha’s top level namespace, which also provides the ability to configure Mocha’s behavior.

Methods in the API are directly available in `Test::Unit::TestCase`, `Minitest::Unit::TestCase`.

The mock creation methods are mock, stub and stub_everything, all of which return a Mock

A Mock expects or stubs a method, which sets up (returns) an Expectation.

An Expectation can be further qualified through its fluent interface.

ParameterMatchers for Expectation#with restrict the parameter values which will match the Expectation.

Adapters in Integration provide built-in support for `Minitest` and `Test::Unit`.

Integration Hooks enable support for other test frameworks.

## Defined Under Namespace

Modules: API, ClassMethods, Hooks, Integration, ObjectMethods, ParameterMatchers Classes: Configuration, Expectation, ExpectationError, ExpectationErrorFactory, Mock, Sequence, StateMachine, StubbingError

## Class Method Summary collapse

- .configure {|configuration| ... } ⇒ Object

  Allows setting of configuration options.

## Class Method Details

### .configure {|configuration| ... } ⇒ `Object`

Allows setting of configuration options. See Configuration for the available options.

Typically the configuration is set globally in a `test_helper.rb` or `spec_helper.rb` file.

#### Examples:

#####

Setting multiple configuration options

    Mocha.configure do |c|
      c.stubbing_method_unnecessarily = :prevent
      c.stubbing_method_on_non_mock_object = :warn
    end

Yield Parameters:

- configuration (`Configuration`) —

  the configuration for modification

See Also:

- Configuration

    21
    22
    23
    # File 'lib/mocha/configuration.rb', line 21

    def self.configure
      yield configuration
    end