class RSpec::Mocks::Space

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/rspec/mocks/space.rbs

class RSpec::Mocks::Space
  def new_mutex: () -> RSpec::Support::ReentrantMutex
  def verify_all: () -> untyped
end

@private

def any_instance_proxy_for(klass)

def any_instance_proxy_for(klass)
  AnyInstance::Proxy.new(any_instance_recorder_for(klass), proxies_of(klass))
end

def any_instance_recorder_for(klass, only_return_existing=false)

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

def any_instance_recorder_not_found_for(id, klass)

def any_instance_recorder_not_found_for(id, klass)
  any_instance_recorders[id] = AnyInstance::Recorder.new(klass)
end

def any_instance_recorders_from_ancestry_of(object)

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

def class_proxy_with_callback_verification_strategy(object, strategy)

def class_proxy_with_callback_verification_strategy(object, strategy)
  if RSpec::Mocks.configuration.verify_partial_doubles?
    VerifyingPartialClassDoubleProxy.new(
      self,
      object,
      @expectation_ordering,
      strategy
    )
  else
    PartialClassDoubleProxy.new(self, object, @expectation_ordering)
  end
end

def constant_mutator_for(name)

def constant_mutator_for(name)
  @constant_mutators.find { |m| m.full_constant_name == name }
end

def id_for(object)

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_exec do
    @__id_for_rspec_mocks_space ||= ::SecureRandom.uuid
  end
end

def id_for(object)

def id_for(object)
  object.__id__
end

def initialize

def initialize
  @proxies                 = {}
  @any_instance_recorders  = {}
  @constant_mutators       = []
  @expectation_ordering    = OrderGroup.new
  @proxy_mutex             = new_mutex
  @any_instance_mutex      = new_mutex
end

def new_mutex

Experimental RBS support (using type sampling data from the type_fusion project).

def new_mutex: () -> RSpec::Support::ReentrantMutex

This signature was generated using 1 sample from 1 application.

def new_mutex
  Support::ReentrantMutex.new
end

def new_scope

def new_scope
  NestedSpace.new(self)
end

def proxies_of(klass)

def proxies_of(klass)
  proxies.values.select { |proxy| klass === proxy.object }
end

def proxy_for(object)

def proxy_for(object)
  proxy_mutex.synchronize do
    id = id_for(object)
    proxies.fetch(id) { proxy_not_found_for(id, object) }
  end
end

def proxy_not_found_for(id, object)

def proxy_not_found_for(id, object)
  proxies[id] = case object
                when NilClass   then ProxyForNil.new(@expectation_ordering)
                when TestDouble then object.__build_mock_proxy_unless_expired(@expectation_ordering)
                when Class
                  class_proxy_with_callback_verification_strategy(object, CallbackInvocationStrategy.new)
                else
                  if RSpec::Mocks.configuration.verify_partial_doubles?
                    VerifyingPartialDoubleProxy.new(object, @expectation_ordering)
                  else
                    PartialDoubleProxy.new(object, @expectation_ordering)
                  end
                end
end

def register_constant_mutator(mutator)

def register_constant_mutator(mutator)
  @constant_mutators << mutator
end

def registered?(object)

def registered?(object)
  proxies.key?(id_for object)
end

def reset_all

def reset_all
  proxies.each_value { |proxy| proxy.reset }
  any_instance_recorders.each_value { |recorder| recorder.stop_all_observation! }
  any_instance_recorders.clear
  @constant_mutators.reverse.each { |mut| mut.idempotently_reset }
end

def superclass_proxy_for(klass)

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

def superclass_proxy_not_found_for(id, object)

def superclass_proxy_not_found_for(id, object)
  raise "superclass_proxy_not_found_for called with something that is not a class" unless Class === object
  proxies[id] = class_proxy_with_callback_verification_strategy(object, NoCallbackInvocationStrategy.new)
end

def verify_all

Experimental RBS support (using type sampling data from the type_fusion project).

def verify_all: () -> untyped

This signature was generated using 1 sample from 1 application.

def verify_all
  proxies.values.each { |proxy| proxy.verify }
  any_instance_recorders.each_value { |recorder| recorder.verify }
end