Module: RSpec::Mocks

### Home Classes Methods

### In Files

- lib/rspec/mocks.rb
- lib/rspec/mocks/any_instance/chain.rb
- lib/rspec/mocks/any_instance/expectation_chain.rb
- lib/rspec/mocks/any_instance/message_chains.rb
- lib/rspec/mocks/any_instance/recorder.rb
- lib/rspec/mocks/any_instance/stub_chain.rb
- lib/rspec/mocks/any_instance/stub_chain_chain.rb
- lib/rspec/mocks/argument_list_matcher.rb
- lib/rspec/mocks/argument_matchers.rb
- lib/rspec/mocks/configuration.rb
- lib/rspec/mocks/deprecation.rb
- lib/rspec/mocks/error_generator.rb
- lib/rspec/mocks/errors.rb
- lib/rspec/mocks/example_methods.rb
- lib/rspec/mocks/extensions/instance_exec.rb
- lib/rspec/mocks/instance_method_stasher.rb
- lib/rspec/mocks/matchers/have_received.rb
- lib/rspec/mocks/matchers/receive.rb
- lib/rspec/mocks/message_expectation.rb
- lib/rspec/mocks/method_double.rb
- lib/rspec/mocks/mock.rb
- lib/rspec/mocks/mutate_const.rb
- lib/rspec/mocks/order_group.rb
- lib/rspec/mocks/proxy.rb
- lib/rspec/mocks/space.rb
- lib/rspec/mocks/proxy_for_nil.rb
- lib/rspec/mocks/stub_chain.rb
- lib/rspec/mocks/syntax.rb
- lib/rspec/mocks/targets.rb
- lib/rspec/mocks/test_double.rb
- lib/rspec/mocks/version.rb

### Namespace

- MODULE RSpec::Mocks::AnyInstance
- MODULE RSpec::Mocks::ArgumentMatchers
- MODULE RSpec::Mocks::Deprecation
- MODULE RSpec::Mocks::ExampleMethods
- MODULE RSpec::Mocks::InstanceExec
- MODULE RSpec::Mocks::Matchers
- MODULE RSpec::Mocks::RecursiveConstMethods
- MODULE RSpec::Mocks::Syntax
- MODULE RSpec::Mocks::TestDouble
- MODULE RSpec::Mocks::Version
- CLASS RSpec::Mocks::AllowanceTarget
- CLASS RSpec::Mocks::AmbiguousReturnError
- CLASS RSpec::Mocks::AndCallOriginalImplementation
- CLASS RSpec::Mocks::AndReturnImplementation
- CLASS RSpec::Mocks::AndYieldImplementation
- CLASS RSpec::Mocks::AnyInstanceAllowanceTarget
- CLASS RSpec::Mocks::AnyInstanceExpectationTarget
- CLASS RSpec::Mocks::ArgumentListMatcher
- CLASS RSpec::Mocks::Configuration
- CLASS RSpec::Mocks::Constant
- CLASS RSpec::Mocks::ConstantMutator
- CLASS RSpec::Mocks::ConstantStubber
- CLASS RSpec::Mocks::ErrorGenerator
- CLASS RSpec::Mocks::ExpectationTarget
- CLASS RSpec::Mocks::Implementation
- CLASS RSpec::Mocks::InstanceMethodStasher
- CLASS RSpec::Mocks::MessageExpectation
- CLASS RSpec::Mocks::MethodDouble
- CLASS RSpec::Mocks::Mock
- CLASS RSpec::Mocks::MockExpectationError
- CLASS RSpec::Mocks::OrderGroup
- CLASS RSpec::Mocks::Proxy
- CLASS RSpec::Mocks::ProxyForNil
- CLASS RSpec::Mocks::Space
- CLASS RSpec::Mocks::StubChain
- CLASS RSpec::Mocks::TargetBase

### Methods

- ::allow_message
- ::any_instance_recorder_for
- ::configuration
- ::expect_message
- ::method_handle_for
- ::proxy_for
- ::setup
- ::teardown
- ::verify

### Included Modules

- RSpec::Mocks::ExampleMethods

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Mocks
- RSpec::Mocks::AllowanceTarget
- RSpec::Mocks::AmbiguousReturnError
- RSpec::Mocks::AndCallOriginalImplementation
- RSpec::Mocks::AndReturnImplementation
- RSpec::Mocks::AndYieldImplementation
- RSpec::Mocks::AnyInstance
- RSpec::Mocks::AnyInstance::Chain
- RSpec::Mocks::AnyInstance::Chain::Customizations
- RSpec::Mocks::AnyInstance::ExpectationChain
- RSpec::Mocks::AnyInstance::MessageChains
- RSpec::Mocks::AnyInstance::PositiveExpectationChain
- 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::BooleanMatcher
- RSpec::Mocks::ArgumentMatchers::DuckTypeMatcher
- RSpec::Mocks::ArgumentMatchers::EqualityProxy
- RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
- RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::InstanceOf
- RSpec::Mocks::ArgumentMatchers::KindOf
- RSpec::Mocks::ArgumentMatchers::MatcherMatcher
- RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
- RSpec::Mocks::ArgumentMatchers::RegexpMatcher
- 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::ConstantStubber
- RSpec::Mocks::Deprecation
- RSpec::Mocks::ErrorGenerator
- RSpec::Mocks::ExampleMethods
- RSpec::Mocks::ExampleMethods::ExpectHost
- RSpec::Mocks::ExpectationTarget
- RSpec::Mocks::Implementation
- RSpec::Mocks::InstanceExec
- RSpec::Mocks::InstanceMethodStasher
- RSpec::Mocks::Matchers
- RSpec::Mocks::Matchers::HaveReceived
- RSpec::Mocks::Matchers::Receive
- RSpec::Mocks::Matchers::Receive::Customization
- RSpec::Mocks::MessageExpectation
- RSpec::Mocks::MethodDouble
- RSpec::Mocks::MethodDouble::ProcWithBlock
- RSpec::Mocks::Mock
- RSpec::Mocks::MockExpectationError
- RSpec::Mocks::OrderGroup
- RSpec::Mocks::Proxy
- RSpec::Mocks::ProxyForNil
- RSpec::Mocks::RecursiveConstMethods
- RSpec::Mocks::Space
- RSpec::Mocks::StubChain
- RSpec::Mocks::Syntax
- RSpec::Mocks::TargetBase
- RSpec::Mocks::TestDouble
- RSpec::Mocks::Version
- Marshal

No matching classes.

# RSpec::Mocks

### Constants

ConstantStubber

  Keeps backwards compatibility since we had released an rspec-mocks that only supported stubbing. Later, we released the hide_const feature and decided that the term "mutator" was a better term to wrap up the concept of both stubbing and hiding.

IGNORED_BACKTRACE_LINE

  @private

KERNEL_METHOD_METHOD

  @api private

NegationUnsupportedError
UnsupportedMatcherError

### Attributes

space[RW]

### Public Class Methods

allow_message(subject, message, opts={}, &block) click to toggle source

Adds an allowance (stub) on `subject`

@param subject the subject to which the message will be added @param message a symbol, representing the message that will be

    added.

@param opts a hash of options, :expected_from is used to set the

    original call site

@param block an optional implementation for the allowance

@example Defines the implementation of `foo` on `bar`, using the passed block

    x = 0
    RSpec::Mocks.allow_message(bar, :foo) { x += 1 }

    # File lib/rspec/mocks.rb, line 45
    def allow_message(subject, message, opts={}, &block)
      orig_caller = opts.fetch(:expected_from) { caller(1)[0] }
      ::RSpec::Mocks.proxy_for(subject).
        add_stub(orig_caller, message.to_sym, opts, &block)
    end

any_instance_recorder_for(klass) click to toggle source

    # File lib/rspec/mocks.rb, line 29
    def any_instance_recorder_for(klass)
      space.any_instance_recorder_for(klass)
    end

configuration() click to toggle source

    # File lib/rspec/mocks/configuration.rb, line 48
    def self.configuration
      @configuration ||= Configuration.new
    end

expect_message(subject, message, opts={}, &block) click to toggle source

Sets a message expectation on `subject`. @param subject the subject on which the message will be expected @param message a symbol, representing the message that will be

    expected.

@param opts a hash of options, :expected_from is used to set the

    original call site

@param block an optional implementation for the expectation

@example Expect the message `foo` to receive `bar`, then call it

    RSpec::Mocks.expect_message(bar, :foo)
    bar.foo

    # File lib/rspec/mocks.rb, line 62
    def expect_message(subject, message, opts={}, &block)
      orig_caller = opts.fetch(:expected_from) { caller(1)[0] }
      ::RSpec::Mocks.proxy_for(subject).
        add_message_expectation(orig_caller, message.to_sym, opts, &block)
    end

method_handle_for(object, method_name) click to toggle source

@api private Used internally to get a method handle for a particular object and method name.

Includes handling for a few special cases:

    - Objects that redefine #method (e.g. an HTTPRequest struct)
    - BasicObject subclasses that mixin a Kernel dup (e.g. SimpleDelegator)

    # File lib/rspec/mocks.rb, line 79
    def method_handle_for(object, method_name)
      if ::Kernel === object
        KERNEL_METHOD_METHOD.bind(object).call(method_name)
      else
        object.method(method_name)
      end
    end

proxy_for(object) click to toggle source

    # File lib/rspec/mocks.rb, line 25
    def proxy_for(object)
      space.proxy_for(object)
    end

setup(host) click to toggle source

    # File lib/rspec/mocks.rb, line 10
    def setup(host)
      (class << host; self; end).class_eval do
        include RSpec::Mocks::ExampleMethods
      end
      self.space ||= RSpec::Mocks::Space.new
    end

teardown() click to toggle source

    # File lib/rspec/mocks.rb, line 21
    def teardown
      space.reset_all
    end

verify() click to toggle source

    # File lib/rspec/mocks.rb, line 17
    def verify
      space.verify_all
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.