class

Mocks::Registry

Inherits Reference < Object

Stores and retrieves method stubs and calls for multiple objects.

Reference-based objects are tracked by their #object_id (memory address). Value-based objects are tracked by their byte-wise representation.

NOTE: This approach does not work for mutable values, and their use is generally discouraged. This also implies that two separate values with the same content will be tracked as the same object.

See: https://crystal-lang.org/reference/latest/syntax_and_semantics/structs.html

Instance methods

add_call(object, call : Call) : Nil

Records a method call made to an object.

Source
add_stub(object, stub : Stub) : Nil

Adds a stub for an object.

Source
calls(object) : Enumerable

Retrieves all method calls made to an object.

Source
clear(object) : Nil

Removes all stored stubs and calls for the specified object.

Source
clear

Removes all stored stubs and calls for all objects.

Source
clear_calls(object) : Nil

Removes all previously recorded method calls for an object.

Source
clear_stubs(object) : Nil

Removes all previously stubs added for an object.

Source
find_stub(object, call : Call) : Stub | Nil

Finds a stub suitable stub for a method call. Returns nil if no stub was found. Stubs are searched in reverse order so that newly define stubs take precedence.

Source
has_stub?(object, method_name : Symbol)

Checks if an object has a stub configured for the specified method.

Source
remove_stub(object, stub : Stub) : Nil

Removes a stub from an object.

Source

Nested types