class Mocks::Registry

Overview

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/1.7/syntax_and_semantics/structs.html

Defined in:

mocks/registry.cr

Instance Method Summary

Instance Method Detail

def add_call(object, call : Call) : Nil #

Records a method call made to an object.


[View source]
def add_stub(object, stub : Stub) : Nil #

Adds a stub for an object.


[View source]
def calls(object) : Enumerable #

Retrieves all method calls made to an object.


[View source]
def clear(object) : Nil #

Removes all stored stubs and calls for the specified object.


[View source]
def clear : Nil #

Removes all stored stubs and calls for all objects.


[View source]
def clear_calls(object) : Nil #

Removes all previously recorded method calls for an object.


[View source]
def clear_stubs(object) : Nil #

Removes all previously stubs added for an object.


[View source]
def 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.


[View source]
def has_stub?(object, method_name : Symbol) #

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


[View source]
def remove_stub(object, stub : Stub) : Nil #

Removes a stub from an object.


[View source]