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)
Redefinition of Spectator::Double.class#new
-
.new(**value_methods)
Redefinition of Spectator::Double.class#new
-
.unsafe_construct(address : Pointer, *args, **opts) : self
Redefinition of Reference.class#unsafe_construct
Class Method Summary
-
._spectator_calls : Array(MethodCall)
Retrieves all previously saved calls.
-
.from_json(string_or_io, root : String)
Redefinition of Object.class#from_json
-
.from_json(string_or_io)
Redefinition of Object.class#from_json
-
.pre_initialize(address : Pointer)
Redefinition of Reference.class#pre_initialize
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 Method Summary
-
#!=(other)
Redefinition of Object#!=
-
#!~(other)
Redefinition of Object#!~
-
#==(other : self)
Redefinition of Reference#==
-
#==(other : JSON::Any)
Redefinition of Reference#==
-
#==(other)
Redefinition of Reference#==
-
#===(other : JSON::Any)
Redefinition of Object#===
-
#===(other)
Redefinition of Object#===
-
#=~(other)
Redefinition of Object#=~
-
#_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)
Redefinition of Colorize::ObjectExtensions#colorize
-
#colorize(fore : UInt8)
Redefinition of Colorize::ObjectExtensions#colorize
-
#colorize(fore : Symbol)
Redefinition of Colorize::ObjectExtensions#colorize
-
#colorize(fore : Color)
Redefinition of Colorize::ObjectExtensions#colorize
-
#colorize : Colorize::Object
Redefinition of Colorize::ObjectExtensions#colorize
-
#crystal_type_id : Int32
Redefinition of Object#crystal_type_id
-
#dup
Redefinition of Reference#dup
-
#hash(hasher)
Redefinition of Reference#hash
-
#hash
Redefinition of Object#hash
-
#in?(collection : Object) : Bool
Redefinition of Object#in?
-
#in?(*values : Object) : Bool
Redefinition of Object#in?
-
#inspect(io : IO) : Nil
Redefinition of Spectator::Double#inspect
-
#inspect : String
Redefinition of Object#inspect
-
#itself
Redefinition of Object#itself
-
#not_nil!(message)
Redefinition of Object#not_nil!
-
#not_nil!
Redefinition of Object#not_nil!
-
#object_id : UInt64
Redefinition of Reference#object_id
-
#pretty_inspect(width = 79, newline = "\n", indent = 0) : String
Redefinition of Object#pretty_inspect
-
#pretty_print(pp : PrettyPrint) : Nil
Redefinition of Object#pretty_print
-
#pretty_print(pp) : Nil
Redefinition of Reference#pretty_print
-
#same?(other : Reference) : Bool
Redefinition of Reference#same?
-
#same?(other : Nil)
Redefinition of Reference#same?
-
#same?(other) : Bool
Redefinition of Spectator::Double#same?
-
#should(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
Redefinition of Object#should
-
#should(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
Redefinition of Object#should
-
#should_eventually(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
Redefinition of Object#should_eventually
-
#should_never(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
Redefinition of Object#should_never
-
#should_not(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
Redefinition of Object#should_not
-
#should_not(matcher : Spectator::Matchers::NilMatcher, message = nil, *, _file = __FILE__, _line = __LINE__)
Redefinition of Object#should_not
-
#should_not(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
Redefinition of Object#should_not
-
#tap(&)
Redefinition of Object#tap
-
#to_json(io : IO) : Nil
Redefinition of Object#to_json
-
#to_json : String
Redefinition of Object#to_json
-
#to_pretty_json(indent : String = " ") : String
Redefinition of Object#to_pretty_json
-
#to_pretty_json(io : IO, indent : String = " ") : Nil
Redefinition of Object#to_pretty_json
-
#to_s(io : IO) : Nil
Redefinition of Spectator::Double#to_s
-
#to_s : String
Redefinition of Object#to_s
-
#try(&)
Redefinition of Object#try
-
#unsafe_as(type : T.class) forall T
Redefinition of Object#unsafe_as
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 methods inherited from class Object
should(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall Ushould(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should, should_eventually(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_eventually, should_never(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_never, should_not(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
should_not(matcher : Spectator::Matchers::NilMatcher, message = nil, *, _file = __FILE__, _line = __LINE__)
should_not(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_not
Constructor Detail
Redefinition of Spectator::Double.class#new
Redefinition of Reference.class#unsafe_construct
Class Method Detail
Retrieves all previously saved calls.
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.
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.
Redefinition of Object#pretty_inspect
Redefinition of Object#should
Redefinition of Object#should
Redefinition of Object#should_eventually
Redefinition of Object#should_never
Redefinition of Object#should_not
Redefinition of Object#should_not
Redefinition of Object#should_not