Class: RSpec::Mocks::Configuration

### Home Classes Methods

### In Files

- lib/rspec/mocks/configuration.rb

### Parent

Object

### Methods

- ::new
- #add_stub_and_should_receive_to
- #before_verifying_doubles
- #color?
- #patch_marshal_to_support_partial_doubles=
- #reset_syntaxes_to_default
- #syntax
- #syntax=
- #transfer_nested_constants?
- #verify_doubled_constant_names?
- #verify_partial_doubles=
- #verify_partial_doubles?
- #verifying_double_callbacks
- #when_declaring_verifying_double
- #yield_receiver_to_any_instance_implementation_blocks?

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Mocks
- RSpec::Mocks::AllowanceTarget
- RSpec::Mocks::AndReturnImplementation
- RSpec::Mocks::AndWrapOriginalImplementation
- RSpec::Mocks::AndYieldImplementation
- RSpec::Mocks::AnyInstance
- RSpec::Mocks::AnyInstance::Chain
- RSpec::Mocks::AnyInstance::Chain::Customizations
- RSpec::Mocks::AnyInstance::ErrorGenerator
- RSpec::Mocks::AnyInstance::ExpectChainChain
- RSpec::Mocks::AnyInstance::ExpectationChain
- RSpec::Mocks::AnyInstance::FluentInterfaceProxy
- RSpec::Mocks::AnyInstance::MessageChains
- RSpec::Mocks::AnyInstance::PositiveExpectationChain
- RSpec::Mocks::AnyInstance::Proxy
- RSpec::Mocks::AnyInstance::Recorder
- RSpec::Mocks::AnyInstance::StubChain
- RSpec::Mocks::AnyInstance::StubChainChain
- RSpec::Mocks::AnyInstanceAllowanceTarget
- RSpec::Mocks::AnyInstanceExpectationTarget
- RSpec::Mocks::ArgumentListMatcher
- RSpec::Mocks::ArgumentMatchers
- RSpec::Mocks::ArgumentMatchers::AnyArgMatcher
- RSpec::Mocks::ArgumentMatchers::AnyArgsMatcher
- RSpec::Mocks::ArgumentMatchers::ArrayIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::BaseHashMatcher
- RSpec::Mocks::ArgumentMatchers::BooleanMatcher
- RSpec::Mocks::ArgumentMatchers::DuckTypeMatcher
- RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
- RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::InstanceOf
- RSpec::Mocks::ArgumentMatchers::KindOf
- RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
- RSpec::Mocks::ArgumentMatchers::SingletonMatcher
- RSpec::Mocks::CallbackInvocationStrategy
- RSpec::Mocks::ClassNewMethodReference
- RSpec::Mocks::ClassVerifyingDouble
- RSpec::Mocks::Configuration
- RSpec::Mocks::Constant
- RSpec::Mocks::ConstantMutator
- RSpec::Mocks::ConstantMutator::BaseMutator
- RSpec::Mocks::ConstantMutator::ConstantHider
- RSpec::Mocks::ConstantMutator::DefinedConstantReplacer
- RSpec::Mocks::ConstantMutator::UndefinedConstantSetter
- RSpec::Mocks::DirectObjectReference
- RSpec::Mocks::Double
- RSpec::Mocks::ErrorGenerator
- RSpec::Mocks::ExampleMethods
- RSpec::Mocks::ExampleMethods::ExpectHost
- RSpec::Mocks::ExpectChain
- RSpec::Mocks::ExpectationTarget
- RSpec::Mocks::Implementation
- RSpec::Mocks::InstanceMethodReference
- RSpec::Mocks::InstanceMethodStasher
- RSpec::Mocks::InstanceVerifyingDouble
- RSpec::Mocks::MarshalExtension
- RSpec::Mocks::Matchers
- RSpec::Mocks::Matchers::ExpectationCustomization
- RSpec::Mocks::Matchers::HaveReceived
- RSpec::Mocks::Matchers::Receive
- RSpec::Mocks::Matchers::Receive::DefaultDescribable
- RSpec::Mocks::Matchers::ReceiveMessageChain
- RSpec::Mocks::Matchers::ReceiveMessages
- RSpec::Mocks::MessageChain
- RSpec::Mocks::MessageExpectation
- RSpec::Mocks::MessageExpectation::ImplementationDetails
- RSpec::Mocks::MethodDouble
- RSpec::Mocks::MethodReference
- RSpec::Mocks::Mutex
- RSpec::Mocks::NamedObjectReference
- RSpec::Mocks::NestedSpace
- RSpec::Mocks::NoCallbackInvocationStrategy
- RSpec::Mocks::ObjectMethodReference
- RSpec::Mocks::ObjectReference
- RSpec::Mocks::ObjectVerifyingDouble
- RSpec::Mocks::ObjectVerifyingDoubleMethods
- RSpec::Mocks::OrderGroup
- RSpec::Mocks::PartialClassDoubleProxy
- RSpec::Mocks::PartialClassDoubleProxyMethods
- RSpec::Mocks::PartialDoubleProxy
- RSpec::Mocks::Proxy
- RSpec::Mocks::ProxyForNil
- RSpec::Mocks::ReentrantMutex
- RSpec::Mocks::RootSpace
- RSpec::Mocks::SimpleMessageExpectation
- RSpec::Mocks::Space
- RSpec::Mocks::StubChain
- RSpec::Mocks::Syntax
- RSpec::Mocks::TargetBase
- RSpec::Mocks::TestDouble
- RSpec::Mocks::TestDoubleFormatter
- RSpec::Mocks::TestDoubleProxy
- RSpec::Mocks::VerifyingDouble
- RSpec::Mocks::VerifyingDouble::SilentIO
- RSpec::Mocks::VerifyingExistingClassNewMethodDouble
- RSpec::Mocks::VerifyingExistingMethodDouble
- RSpec::Mocks::VerifyingMessageExpectation
- RSpec::Mocks::VerifyingMethodDouble
- RSpec::Mocks::VerifyingPartialClassDoubleProxy
- RSpec::Mocks::VerifyingPartialDoubleProxy
- RSpec::Mocks::VerifyingProxy
- RSpec::Mocks::VerifyingProxyMethods
- RSpec::Mocks::Version
- BasicObject
- Class

No matching classes.

# RSpec::Mocks::Configuration

Provides configuration options for rspec-mocks.

### Attributes

transfer_nested_constants[W]

Sets the default for the `transfer_nested_constants` option when stubbing constants.

verify_doubled_constant_names[W]

When this is set to true, an error will be raised when `instance_double` or `class_double` is given the name of an undefined constant. You probably only want to set this when running your entire test suite, with all production code loaded. Setting this for an isolated unit test will prevent you from being able to isolate it!

yield_receiver_to_any_instance_implementation_blocks[W]

Sets whether or not RSpec will yield the receiving instance of a message to blocks that are used for any_instance stub implementations. When set, the first yielded argument will be the receiving instance. Defaults to `true`.

@example

    RSpec.configure do |rspec|
      rspec.mock_with :rspec do |mocks|
        mocks.yield_receiver_to_any_instance_implementation_blocks = false
      end
    end

### Public Class Methods

new() click to toggle source

    # File lib/rspec/mocks/configuration.rb, line 5
    def initialize
      @yield_receiver_to_any_instance_implementation_blocks = true
      @verify_doubled_constant_names = false
      @transfer_nested_constants = false
      @verify_partial_doubles = false
    end

### Public Instance Methods

add_stub_and_should_receive_to(*modules) click to toggle source

Adds `stub` and `should_receive` to the given modules or classes. This is usually only necessary if you application uses some proxy classes that "strip themselves down" to a bare minimum set of methods and remove `stub` and `should_receive` in the process.

@example

    RSpec.configure do |rspec|
      rspec.mock_with :rspec do |mocks|
        mocks.add_stub_and_should_receive_to Delegator
      end
    end

    # File lib/rspec/mocks/configuration.rb, line 43
    def add_stub_and_should_receive_to(*modules)
      modules.each do |mod|
        Syntax.enable_should(mod)
      end
    end

before_verifying_doubles(&block) click to toggle source

Provides a way to perform customisations when verifying doubles.

@example

    RSpec::Mocks.configuration.before_verifying_doubles do |ref|
      ref.some_method!
    end

    # File lib/rspec/mocks/configuration.rb, line 109
    def before_verifying_doubles(&block)
      verifying_double_callbacks << block
    end

Also aliased as: when_declaring_verifying_double
color?() click to toggle source

    # File lib/rspec/mocks/configuration.rb, line 140
    def color?
      ::RSpec.configuration.color_enabled?
    end

patch_marshal_to_support_partial_doubles=(val) click to toggle source

Monkey-patch `Marshal.dump` to enable dumping of mocked or stubbed objects. By default this will not work since RSpec mocks works by adding singleton methods that cannot be serialized. This patch removes these singleton methods before serialization. Setting to falsey removes the patch.

This method is idempotent.

    # File lib/rspec/mocks/configuration.rb, line 164
    def patch_marshal_to_support_partial_doubles=(val)
      if val
        RSpec::Mocks::MarshalExtension.patch!
      else
        RSpec::Mocks::MarshalExtension.unpatch!
      end
    end

reset_syntaxes_to_default() click to toggle source

@api private Resets the configured syntax to the default.

    # File lib/rspec/mocks/configuration.rb, line 174
    def reset_syntaxes_to_default
      self.syntax = [:should, :expect]
      RSpec::Mocks::Syntax.warn_about_should!
    end

syntax() click to toggle source

Returns an array with a list of syntaxes that are enabled.

@example

    unless RSpec::Mocks.configuration.syntax.include?(:expect)
      raise "this RSpec extension gem requires the rspec-mocks `:expect` syntax"
    end

    # File lib/rspec/mocks/configuration.rb, line 85
    def syntax
      syntaxes = []
      syntaxes << :should  if Syntax.should_enabled?
      syntaxes << :expect if Syntax.expect_enabled?
      syntaxes
    end

syntax=(*values) click to toggle source

Provides the ability to set either `expect`, `should` or both syntaxes. RSpec uses `expect` syntax by default. This is needed if you want to explicitly enable `should` syntax and/or explicitly disable `expect` syntax.

@example

     RSpec.configure do |rspec|
       rspec.mock_with :rspec do |mocks|
         mocks.syntax = [:expect, :should]
       end
    end

    # File lib/rspec/mocks/configuration.rb, line 62
    def syntax=(*values)
      syntaxes = values.flatten
      if syntaxes.include?(:expect)
        Syntax.enable_expect
      else
        Syntax.disable_expect
      end

      if syntaxes.include?(:should)
        Syntax.enable_should
      else
        Syntax.disable_should
      end
    end

transfer_nested_constants?() click to toggle source

    # File lib/rspec/mocks/configuration.rb, line 120
    def transfer_nested_constants?
      !!@transfer_nested_constants
    end

verify_doubled_constant_names?() click to toggle source

    # File lib/rspec/mocks/configuration.rb, line 92
    def verify_doubled_constant_names?
      !!@verify_doubled_constant_names
    end

verify_partial_doubles=(val) click to toggle source

When set to true, partial mocks will be verified the same as object doubles. Any stubs will have their arguments checked against the original method, and methods that do not exist cannot be stubbed.

    # File lib/rspec/mocks/configuration.rb, line 131
    def verify_partial_doubles=(val)
      @verify_partial_doubles = !!val
    end

verify_partial_doubles?() click to toggle source

    # File lib/rspec/mocks/configuration.rb, line 135
    def verify_partial_doubles?
      @verify_partial_doubles
    end

verifying_double_callbacks() click to toggle source

@api private Returns an array of blocks to call when verifying doubles

    # File lib/rspec/mocks/configuration.rb, line 116
    def verifying_double_callbacks
      @verifying_double_callbacks ||= []
    end

when_declaring_verifying_double(&block) click to toggle source
Alias for: before_verifying_doubles
yield_receiver_to_any_instance_implementation_blocks?() click to toggle source

    # File lib/rspec/mocks/configuration.rb, line 12
    def yield_receiver_to_any_instance_implementation_blocks?
      @yield_receiver_to_any_instance_implementation_blocks
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.