module

Spectator::Mocked

Inherits Spectator::Stubbable

Mix-in used for mocked types.

Bridges functionality between mocks and stubs Implements the abstracts methods from Stubbable.

Types including this module will need to implement #_spectator_stubs. It should return a mutable list of stubs. This is used to store the stubs for the mocked type.

Additionally, the #_spectator_calls (getter with no arguments) must be implemented. It should return a mutable list of method calls. This is used to store the calls to stubs for the mocked type.

Instance methods

_spectator_abstract_stub_fallback(call : MethodCall, type)

Method called when a stub isn't found.

This is similar to #_spectator_stub_fallback, but called when the original (un-stubbed) method isn't available. The received message is captured in call. The expected return type is provided by type. The stubbed method returns the value returned by this method. This method can also raise an error if it's impossible to return something.

Source
_spectator_abstract_stub_fallback(call : MethodCall)

Method called when a stub isn't found.

This is similar to #_spectator_stub_fallback, but called when the original (un-stubbed) method isn't available. The received message is captured in call. The stubbed method returns the value returned by this method. This method can also raise an error if it's impossible to return something.

Source
_spectator_calls(method : Symbol) : Enumerable(MethodCall)
Source
_spectator_clear_calls

Clears all previously saved calls.

Source
_spectator_clear_stubs

Clears all previously defined stubs.

Source
_spectator_define_stub(stub : Spectator::Stub) : Nil

Defines a stub to change the behavior of a method.

Source
_spectator_record_call(call : MethodCall) : Nil

Saves a call that was made to a stubbed method.

Source
_spectator_remove_stub(stub : Stub) : Nil

Removes a specific, previously defined stub.

Source
_spectator_stub_fallback(call : MethodCall, type, &)

Method called when a stub isn't found.

The received message is captured in call. The expected return type is provided by type. Yield to call the original method's implementation. The stubbed method returns the value returned by this method. This method can also raise an error if it's impossible to return something.

Source
_spectator_stub_fallback(call : MethodCall, &)

Method called when a stub isn't found.

The received message is captured in call. Yield to call the original method's implementation. The stubbed method returns the value returned by this method. This method can also raise an error if it's impossible to return something.

Source
_spectator_stub_for_method?(method : Symbol) : Bool

Utility method that looks for stubs for methods with the name specified.

Source
_spectator_stubs

Retrieves an mutable collection of stubs.

Source