Class: RSpec::Mocks::AnyInstance::Proxy

### Home Classes Methods

### In Files

- lib/rspec/mocks/any_instance/proxy.rb

### Parent

Object

### Methods

- ::new
- #expect_chain
- #klass
- #should_not_receive
- #should_receive
- #stub
- #stub_chain
- #unstub

### 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::AnyInstance::Proxy

@private The `AnyInstance::Recorder` is responsible for redefining the klass's instance method in order to add any stubs/expectations the first time the method is called. It's not capable of updating a stub on an instance that's already been previously stubbed (either directly, or via `any_instance`).

This proxy sits in front of the recorder and delegates both to it and to the `RSpec::Mocks::Proxy` for each already mocked or stubbed instance of the class, in order to propogates changes to the instances.

Note that unlike `RSpec::Mocks::Proxy`, this proxy class is stateless and is not persisted in `RSpec::Mocks.space`.

Proxying for the message expectation fluent interface (typically chained off of the return value of one of these methods) is provided by the `FluentInterfaceProxy` class below.

### Public Class Methods

new(recorder, target_proxies) click to toggle source

    # File lib/rspec/mocks/any_instance/proxy.rb, line 22
    def initialize(recorder, target_proxies)
      @recorder       = recorder
      @target_proxies = target_proxies
    end

### Public Instance Methods

expect_chain(*chain, &block) click to toggle source

    # File lib/rspec/mocks/any_instance/proxy.rb, line 55
    def expect_chain(*chain, &block)
      perform_proxying(__method__, chain, block) do |proxy|
        Mocks::ExpectChain.expect_chain_on(proxy.object, *chain, &block)
      end
    end

klass() click to toggle source

    # File lib/rspec/mocks/any_instance/proxy.rb, line 27
    def klass
      @recorder.klass
    end

should_not_receive(method_name, &block) click to toggle source

    # File lib/rspec/mocks/any_instance/proxy.rb, line 71
    def should_not_receive(method_name, &block)
      perform_proxying(__method__, [method_name], block) do |proxy|
        proxy.add_message_expectation(method_name, &block).never
      end
    end

should_receive(method_name, &block) click to toggle source

    # File lib/rspec/mocks/any_instance/proxy.rb, line 61
    def should_receive(method_name, &block)
      perform_proxying(__method__, [method_name], block) do |proxy|
        # Yeah, this is a bit odd...but if we used `add_message_expectation`
        # then it would act like `expect_every_instance_of(klass).to receive`.
        # The any_instance recorder takes care of validating that an instance
        # received the message.
        proxy.add_stub(method_name, &block)
      end
    end

stub(method_name_or_method_map, &block) click to toggle source

    # File lib/rspec/mocks/any_instance/proxy.rb, line 31
    def stub(method_name_or_method_map, &block)
      if Hash === method_name_or_method_map
        method_name_or_method_map.each do |method_name, return_value|
          stub(method_name).and_return(return_value)
        end
      else
        perform_proxying(__method__, [method_name_or_method_map], block) do |proxy|
          proxy.add_stub(method_name_or_method_map, &block)
        end
      end
    end

stub_chain(*chain, &block) click to toggle source

    # File lib/rspec/mocks/any_instance/proxy.rb, line 49
    def stub_chain(*chain, &block)
      perform_proxying(__method__, chain, block) do |proxy|
        Mocks::StubChain.stub_chain_on(proxy.object, *chain, &block)
      end
    end

unstub(method_name) click to toggle source

    # File lib/rspec/mocks/any_instance/proxy.rb, line 43
    def unstub(method_name)
      perform_proxying(__method__, [method_name], nil) do |proxy|
        proxy.remove_stub_if_present(method_name)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.