class

Spectator::ReferenceMockRegistry

Inherits Reference / Object

Stores collections of stubs for mocked reference (class) types.

This type is intended for all mocked reference types that have functionality "injected." That is, the type itself has mock functionality bolted on. Adding instance members should be avoided, for instance, it could mess up serialization. This registry works around that by mapping mocks (via their memory address) to a collection of stubs. Doing so prevents adding data to the mocked type.

Constructors

new

Creates an empty registry.

Source

Instance methods

[](object : Reference)

Retrieves all stubs defined for a mocked object.

Source
[]?(object : Reference)

Retrieves all stubs defined for a mocked object or nil if the object isn't mocked yet.

Source
delete(object : Reference) : Nil

Clears all stubs defined for a mocked object.

Source
fetch(object : Reference, & : -> Array(Stub))

Retrieves all stubs defined for a mocked object.

Yields to the block on the first retrieval. This allows a mock to populate the registry with initial stubs.

Source