module Spectator::Mocked

Overview

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.

Included Modules

Defined in:

spectator/mocks/mocked.cr

Instance Method Summary

Instance methods inherited from module Spectator::Stubbable

_spectator_abstract_stub_fallback(call : MethodCall, type)
_spectator_abstract_stub_fallback(call : MethodCall)
_spectator_abstract_stub_fallback
, _spectator_calls _spectator_calls, _spectator_clear_calls : Nil _spectator_clear_calls, _spectator_clear_stubs : Nil _spectator_clear_stubs, _spectator_define_stub(stub : Stub) : Nil _spectator_define_stub, _spectator_find_stub(call : MethodCall) : Stub | Nil _spectator_find_stub, _spectator_record_call(call : MethodCall) : Nil _spectator_record_call, _spectator_remove_stub(stub : Stub) : Nil _spectator_remove_stub, _spectator_reset : Nil _spectator_reset, _spectator_stub_fallback(call : MethodCall, type, &)
_spectator_stub_fallback(call : MethodCall, &)
_spectator_stub_fallback
, _spectator_stub_for_method?(method : Symbol) : Bool _spectator_stub_for_method?, _spectator_stubbed_name : String _spectator_stubbed_name

Macros inherited from module Spectator::Stubbable

stub(method) stub

Instance Method Detail

def _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.


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


[View source]
def _spectator_calls(method : Symbol) : Enumerable(MethodCall) #

[View source]
def _spectator_clear_calls : Nil #
Description copied from module Spectator::Stubbable

Clears all previously saved calls.


[View source]
def _spectator_clear_stubs : Nil #
Description copied from module Spectator::Stubbable

Clears all previously defined stubs.


[View source]
def _spectator_define_stub(stub : Spectator::Stub) : Nil #
Description copied from module Spectator::Stubbable

Defines a stub to change the behavior of a method.


[View source]
def _spectator_record_call(call : MethodCall) : Nil #
Description copied from module Spectator::Stubbable

Saves a call that was made to a stubbed method.


[View source]
def _spectator_remove_stub(stub : Stub) : Nil #
Description copied from module Spectator::Stubbable

Removes a specific, previously defined stub.


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


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


[View source]
def _spectator_stub_for_method?(method : Symbol) : Bool #
Description copied from module Spectator::Stubbable

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


[View source]
abstract def _spectator_stubs #

Retrieves an mutable collection of stubs.


[View source]