# Class: Mocha::Configuration

Inherits:
  Object
  - Object
  - Mocha::Configuration
  show all

Defined in:
  lib/mocha/configuration.rb

## Overview

Configuration settings.

## Constant Summary

DEFAULTS =

      {
        :stubbing_method_unnecessarily => :allow,
        :stubbing_method_on_non_mock_object => :allow,
        :stubbing_non_existent_method => :allow,
        :stubbing_non_public_method => :allow,
        :stubbing_method_on_nil => :prevent,
      }

## Class Method Summary collapse

- .allow(action) { ... } ⇒ Object

  Allow the specified `action`.

- .prevent(action) { ... } ⇒ Object

  Raise a StubbingError if if the specified `action` is attempted.

- .warn_when(action) { ... } ⇒ Object

  Warn if the specified `action` is attempted.

## Class Method Details

### .allow(action) { ... } ⇒ `Object`

Allow the specified `action`.

Parameters:

- action (`Symbol`) —

  one of `:stubbing_method_unnecessarily`, `:stubbing_method_on_non_mock_object`, `:stubbing_non_existent_method`, `:stubbing_non_public_method`, `:stubbing_method_on_nil`.

Yields:

- optional block during which the configuration change will be changed before being returned to its original value at the end of the block.

    20
    21
    22

    # File 'lib/mocha/configuration.rb', line 20

    def allow(action, &block)
      change_config action, :allow, &block
    end

### .prevent(action) { ... } ⇒ `Object`

Raise a StubbingError if if the specified `action` is attempted.

Parameters:

- action (`Symbol`) —

  one of `:stubbing_method_unnecessarily`, `:stubbing_method_on_non_mock_object`, `:stubbing_non_existent_method`, `:stubbing_non_public_method`, `:stubbing_method_on_nil`.

Yields:

- optional block during which the configuration change will be changed before being returned to its original value at the end of the block.

    46
    47
    48

    # File 'lib/mocha/configuration.rb', line 46

    def prevent(action, &block)
      change_config action, :prevent, &block
    end

### .warn_when(action) { ... } ⇒ `Object`

Warn if the specified `action` is attempted.

Parameters:

- action (`Symbol`) —

  one of `:stubbing_method_unnecessarily`, `:stubbing_method_on_non_mock_object`, `:stubbing_non_existent_method`, `:stubbing_non_public_method`, `:stubbing_method_on_nil`.

Yields:

- optional block during which the configuration change will be changed before being returned to its original value at the end of the block.

    33
    34
    35

    # File 'lib/mocha/configuration.rb', line 33

    def warn_when(action, &block)
      change_config action, :warn, &block
    end