abstract class Spectator::Double
- Spectator::Double
- Reference
- Object
Overview
Stands in for an object for testing that a SUT calls expected methods.
Handles all messages (method calls), but only responds to those configured.
Methods called that were not configured will raise UnexpectedMessage
.
Doubles should be defined with the #define
macro.
Use #_spectator_define_stub
to override behavior of a method in the double.
Only methods defined in the double's type can have stubs.
New methods are not defines when a stub is added that doesn't have a matching method name.
Included Modules
Extended Modules
Direct Known Subclasses
Defined in:
spectator/mocks/double.crConstant Summary
-
Log =
Spectator::Log.for(self)
Constructors
-
.new(stubs : Array(Spectator::Stub) = [] of ::Spectator::Stub)
"Hide" existing methods and methods from ancestors by overriding them.
-
.new(**value_methods)
"Hide" existing methods and methods from ancestors by overriding them.
Class Method Summary
-
._spectator_calls : Array(MethodCall)
Retrieves all previously saved calls.
-
.from_json(string_or_io, root : String)
"Hide" existing methods and methods from ancestors by overriding them.
-
.from_json(string_or_io)
"Hide" existing methods and methods from ancestors by overriding them.
Instance Method Summary
-
#!=(other)
"Hide" existing methods and methods from ancestors by overriding them.
-
#!~(other)
"Hide" existing methods and methods from ancestors by overriding them.
-
#==(other : self)
"Hide" existing methods and methods from ancestors by overriding them.
-
#==(other : JSON::Any)
"Hide" existing methods and methods from ancestors by overriding them.
-
#==(other)
"Hide" existing methods and methods from ancestors by overriding them.
-
#===(other : JSON::Any)
"Hide" existing methods and methods from ancestors by overriding them.
-
#===(other)
"Hide" existing methods and methods from ancestors by overriding them.
-
#=~(other)
"Hide" existing methods and methods from ancestors by overriding them.
-
#_spectator_calls : Array(Spectator::MethodCall)
Retrieves all previously saved calls.
-
#_spectator_clear_calls : Nil
Clears all previously saved calls.
-
#_spectator_record_call(call : MethodCall) : Nil
Saves a call that was made to a stubbed method.
-
#_spectator_stub_for_method?(method : Symbol) : Bool
Utility method that looks for stubs for methods with the name specified.
-
#colorize(r : UInt8, g : UInt8, b : UInt8)
"Hide" existing methods and methods from ancestors by overriding them.
-
#colorize(fore : UInt8)
"Hide" existing methods and methods from ancestors by overriding them.
-
#colorize(fore : Symbol)
"Hide" existing methods and methods from ancestors by overriding them.
-
#colorize(fore : Color)
"Hide" existing methods and methods from ancestors by overriding them.
-
#colorize : Colorize::Object
"Hide" existing methods and methods from ancestors by overriding them.
-
#crystal_type_id : Int32
"Hide" existing methods and methods from ancestors by overriding them.
-
#dup
"Hide" existing methods and methods from ancestors by overriding them.
-
#hash(hasher)
"Hide" existing methods and methods from ancestors by overriding them.
-
#hash
"Hide" existing methods and methods from ancestors by overriding them.
-
#in?(collection : Object) : Bool
"Hide" existing methods and methods from ancestors by overriding them.
-
#in?(*values : Object) : Bool
"Hide" existing methods and methods from ancestors by overriding them.
-
#inspect(io : IO) : Nil
"Hide" existing methods and methods from ancestors by overriding them.
-
#inspect : String
"Hide" existing methods and methods from ancestors by overriding them.
-
#itself
"Hide" existing methods and methods from ancestors by overriding them.
-
#not_nil!(message)
"Hide" existing methods and methods from ancestors by overriding them.
-
#not_nil!
"Hide" existing methods and methods from ancestors by overriding them.
-
#object_id : UInt64
"Hide" existing methods and methods from ancestors by overriding them.
-
#pretty_inspect(width = 79, newline = "\n", indent = 0) : String
"Hide" existing methods and methods from ancestors by overriding them.
-
#pretty_print(pp : PrettyPrint) : Nil
"Hide" existing methods and methods from ancestors by overriding them.
-
#pretty_print(pp) : Nil
"Hide" existing methods and methods from ancestors by overriding them.
-
#same?(other : Reference) : Bool
"Hide" existing methods and methods from ancestors by overriding them.
-
#same?(other : Nil)
"Hide" existing methods and methods from ancestors by overriding them.
-
#same?(other) : Bool
"Hide" existing methods and methods from ancestors by overriding them.
-
#should(matcher, message = nil)
"Hide" existing methods and methods from ancestors by overriding them.
-
#should_eventually(matcher, message = nil)
"Hide" existing methods and methods from ancestors by overriding them.
-
#should_never(matcher, message = nil)
"Hide" existing methods and methods from ancestors by overriding them.
-
#should_not(matcher, message = nil)
"Hide" existing methods and methods from ancestors by overriding them.
-
#tap(&)
"Hide" existing methods and methods from ancestors by overriding them.
-
#to_json(io : IO) : Nil
"Hide" existing methods and methods from ancestors by overriding them.
-
#to_json : String
"Hide" existing methods and methods from ancestors by overriding them.
-
#to_pretty_json(indent : String = " ") : String
"Hide" existing methods and methods from ancestors by overriding them.
-
#to_pretty_json(io : IO, indent : String = " ") : Nil
"Hide" existing methods and methods from ancestors by overriding them.
-
#to_s(io : IO) : Nil
"Hide" existing methods and methods from ancestors by overriding them.
-
#to_s : String
"Hide" existing methods and methods from ancestors by overriding them.
-
#try(&)
"Hide" existing methods and methods from ancestors by overriding them.
-
#unsafe_as(type : T.class) forall T
"Hide" existing methods and methods from ancestors by overriding them.
Macro Summary
-
define(type_name, name = nil, **value_methods, &block)
Defines a test double type.
-
method_missing(call)
Handle all methods but only respond to configured messages.
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_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
Instance methods inherited from class Object
should(matcher, message = nil)
should,
should_eventually(matcher, message = nil)
should_eventually,
should_never(matcher, message = nil)
should_never,
should_not(matcher, message = nil)
should_not
Constructor Detail
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
Class Method Detail
Retrieves all previously saved calls.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
Instance Method Detail
Retrieves all previously saved calls.
Clears all previously saved calls.
Saves a call that was made to a stubbed method.
Utility method that looks for stubs for methods with the name specified.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
"Hide" existing methods and methods from ancestors by overriding them.
Macro Detail
Defines a test double type.
The type_name is the name to give the class.
Instances of the double can be named by providing a name.
This can be a symbol, string, or even a type.
See StubbedName
for details.
After the names, a collection of key-value pairs can be given to quickly define methods. Each key is the method name, and the corresponding value is the value returned by the method. These methods accept any arguments. Additionally, these methods can be overridden later with stubs.
Lastly, a block can be provided to define additional methods and stubs. The block is evaluated in the context of the double's class.
Double.define(SomeDouble, meth1: 42, meth2: "foobar") do
stub abstract def meth3 : Symbol
# Default implementation with a dynamic value.
stub def meth4
Time.utc
end
end
Handle all methods but only respond to configured messages.
Raises an UnexpectedMessage
error for non-configures messages.