Class: RSpec::Mocks::Space

### Home Classes Methods

### In Files

- lib/rspec/mocks/space.rb

### Parent

Object

### Methods

- ::new
- #any_instance_recorder_for
- #ensure_registered
- #expectation_ordering
- #id_for
- #proxy_for
- #registered?
- #remove_any_instance_recorder_for
- #reset_all
- #verify_all

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

@api private

### Attributes

any_instance_recorders[R]
proxies[R]

### Public Class Methods

new() click to toggle source

    # File lib/rspec/mocks/space.rb, line 7
    def initialize
      @proxies = {}
      @any_instance_recorders = {}
    end

### Public Instance Methods

any_instance_recorder_for(klass) click to toggle source

    # File lib/rspec/mocks/space.rb, line 38
    def any_instance_recorder_for(klass)
      id = klass.__id__
      any_instance_recorders.fetch(id) do
        any_instance_recorders[id] = AnyInstance::Recorder.new(klass)
      end
    end

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

    # File lib/rspec/mocks/space.rb, line 34
    def expectation_ordering
      @expectation_ordering ||= OrderGroup.new
    end

id_for(object) click to toggle source

    # File lib/rspec/mocks/space.rb, line 70
    def id_for(object)
      id = object.__id__

      return id if object.equal?(::ObjectSpace._id2ref(id))
      # this suggests that object.__id__ is proxying through to some wrapped object

      object.instance_eval do
        @__id_for_rspec_mocks_space ||= ::SecureRandom.uuid
      end
    end

proxy_for(object) click to toggle source

    # File lib/rspec/mocks/space.rb, line 49
    def proxy_for(object)
      id = id_for(object)
      proxies.fetch(id) do
        proxies[id] = case object
                      when NilClass   then ProxyForNil.new
                      when TestDouble then object.__build_mock_proxy
                      else
                        Proxy.new(object)
                      end
      end
    end

Also aliased as: ensure_registered
registered?(object) click to toggle source

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

remove_any_instance_recorder_for(klass) click to toggle source

    # File lib/rspec/mocks/space.rb, line 45
    def remove_any_instance_recorder_for(klass)
      any_instance_recorders.delete(klass.__id__)
    end

reset_all() click to toggle source

    # File lib/rspec/mocks/space.rb, line 22
    def reset_all
      ConstantMutator.reset_all

      proxies.each_value do |object|
        object.reset
      end

      proxies.clear
      any_instance_recorders.clear
      expectation_ordering.clear
    end

verify_all() click to toggle source

    # File lib/rspec/mocks/space.rb, line 12
    def verify_all
      proxies.each_value do |object|
        object.verify
      end

      any_instance_recorders.each_value do |recorder|
        recorder.verify
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.