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.crInstance Method Summary
-
#_spectator_abstract_stub_fallback(call : MethodCall, type)
Method called when a stub isn't found.
-
#_spectator_abstract_stub_fallback(call : MethodCall)
Method called when a stub isn't found.
- #_spectator_calls(method : Symbol) : Enumerable(MethodCall)
-
#_spectator_clear_calls : Nil
Clears all previously saved calls.
-
#_spectator_clear_stubs : Nil
Clears all previously defined stubs.
-
#_spectator_define_stub(stub : Spectator::Stub) : Nil
Defines a stub to change the behavior of a method.
-
#_spectator_record_call(call : MethodCall) : Nil
Saves a call that was made to a stubbed method.
-
#_spectator_remove_stub(stub : Stub) : Nil
Removes a specific, previously defined stub.
-
#_spectator_stub_fallback(call : MethodCall, type, &)
Method called when a stub isn't found.
-
#_spectator_stub_fallback(call : MethodCall, &)
Method called when a stub isn't found.
-
#_spectator_stub_for_method?(method : Symbol) : Bool
Utility method that looks for stubs for methods with the name specified.
-
#_spectator_stubs
Retrieves an mutable collection of stubs.
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
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.
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.
Clears all previously saved calls.
Clears all previously defined stubs.
Defines a stub to change the behavior of a method.
Saves a call that was made to a stubbed method.
Removes a specific, previously defined stub.
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.
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.
Utility method that looks for stubs for methods with the name specified.