Class: RSpec::Mocks::Space

### Home Classes Methods

### In Files

- lib/rspec/mocks/space.rb

### Parent

Object

### Methods

- ::new
- #any_instance_proxy_for
- #any_instance_recorder_for
- #any_instance_recorders_from_ancestry_of
- #constant_mutator_for
- #ensure_registered
- #new_scope
- #proxies_of
- #proxy_for
- #register_constant_mutator
- #registered?
- #reset_all
- #superclass_proxy_for
- #verify_all

### 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::Space

@private

### Attributes

any_instance_mutex[R]
any_instance_recorders[R]
proxies[R]
proxy_mutex[R]

### Public Class Methods

new() click to toggle source

    # File lib/rspec/mocks/space.rb, line 60
    def initialize
      @proxies                 = {}
      @any_instance_recorders  = {}
      @constant_mutators       = []
      @expectation_ordering    = OrderGroup.new
      @proxy_mutex             = new_mutex
      @any_instance_mutex      = new_mutex
    end

### Public Instance Methods

any_instance_proxy_for(klass) click to toggle source

    # File lib/rspec/mocks/space.rb, line 103
    def any_instance_proxy_for(klass)
      AnyInstance::Proxy.new(any_instance_recorder_for(klass), proxies_of(klass))
    end

any_instance_recorder_for(klass, only_return_existing=false) click to toggle source

    # File lib/rspec/mocks/space.rb, line 93
    def any_instance_recorder_for(klass, only_return_existing=false)
      any_instance_mutex.synchronize do
        id = klass.__id__
        any_instance_recorders.fetch(id) do
          return nil if only_return_existing
          any_instance_recorder_not_found_for(id, klass)
        end
      end
    end

any_instance_recorders_from_ancestry_of(object) click to toggle source

    # File lib/rspec/mocks/space.rb, line 131
    def any_instance_recorders_from_ancestry_of(object)
      # Optimization: `any_instance` is a feature we generally
      # recommend not using, so we can often early exit here
      # without doing an O(N) linear search over the number of
      # ancestors in the object's class hierarchy.
      return [] if any_instance_recorders.empty?

      # We access the ancestors through the singleton class, to avoid calling
      # `class` in case `class` has been stubbed.
      (class << object; ancestors; end).map do |klass|
        any_instance_recorders[klass.__id__]
      end.compact
    end

constant_mutator_for(name) click to toggle source

    # File lib/rspec/mocks/space.rb, line 89
    def constant_mutator_for(name)
      @constant_mutators.find { |m| m.full_constant_name == name }
    end

ensure_registered(object) click to toggle source
Alias for: proxy_for
new_scope() click to toggle source

    # File lib/rspec/mocks/space.rb, line 69
    def new_scope
      NestedSpace.new(self)
    end

proxies_of(klass) click to toggle source

    # File lib/rspec/mocks/space.rb, line 107
    def proxies_of(klass)
      proxies.values.select { |proxy| klass === proxy.object }
    end

proxy_for(object) click to toggle source

    # File lib/rspec/mocks/space.rb, line 111
    def proxy_for(object)
      proxy_mutex.synchronize do
        id = id_for(object)
        proxies.fetch(id) { proxy_not_found_for(id, object) }
      end
    end

Also aliased as: ensure_registered
register_constant_mutator(mutator) click to toggle source

    # File lib/rspec/mocks/space.rb, line 85
    def register_constant_mutator(mutator)
      @constant_mutators << mutator
    end

registered?(object) click to toggle source

    # File lib/rspec/mocks/space.rb, line 127
    def registered?(object)
      proxies.key?(id_for object)
    end

reset_all() click to toggle source

    # File lib/rspec/mocks/space.rb, line 78
    def reset_all
      proxies.each_value { |proxy| proxy.reset }
      @constant_mutators.reverse.each { |mut| mut.idempotently_reset }
      any_instance_recorders.each_value { |recorder| recorder.stop_all_observation! }
      any_instance_recorders.clear
    end

superclass_proxy_for(klass) click to toggle source

    # File lib/rspec/mocks/space.rb, line 118
    def superclass_proxy_for(klass)
      proxy_mutex.synchronize do
        id = id_for(klass)
        proxies.fetch(id) { superclass_proxy_not_found_for(id, klass) }
      end
    end

verify_all() click to toggle source

    # File lib/rspec/mocks/space.rb, line 73
    def verify_all
      proxies.values.each { |proxy| proxy.verify }
      any_instance_recorders.each_value { |recorder| recorder.verify }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.