Spectator::Double
Inherits Spectator::Stubbable / Reference / Object
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.
Constants
Constructors
Redefinition of Spectator::Double.class#new
Redefinition of Spectator::Double.class#new
Redefinition of Reference.class#unsafe_construct
Class methods
Redefinition of Object.class#from_json
Redefinition of Object.class#from_json
Redefinition of Reference.class#pre_initialize
Instance methods
Redefinition of Object#!=
Redefinition of Object#!~
Redefinition of Reference#==
Redefinition of Reference#==
Redefinition of Reference#==
Redefinition of Object#===
Redefinition of Object#===
Redefinition of Object#=~
Saves a call that was made to a stubbed method.
Utility method that looks for stubs for methods with the name specified.
Redefinition of Colorize::ObjectExtensions#colorize
Redefinition of Colorize::ObjectExtensions#colorize
Redefinition of Colorize::ObjectExtensions#colorize
Redefinition of Colorize::ObjectExtensions#colorize
Redefinition of Colorize::ObjectExtensions#colorize
Redefinition of Object#crystal_type_id
Redefinition of Reference#dup
Redefinition of Reference#hash
Redefinition of Object#hash
Redefinition of Object#in?
Redefinition of Object#in?
Redefinition of Spectator::Double#inspect
Redefinition of Object#inspect
Redefinition of Object#itself
Redefinition of Object#not_nil!
Redefinition of Object#not_nil!
Redefinition of Reference#object_id
Redefinition of Object#pretty_inspect
Redefinition of Object#pretty_print
Redefinition of Reference#pretty_print
Redefinition of Reference#same?
Redefinition of Reference#same?
Redefinition of Spectator::Double#same?
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
Redefinition of Object#tap
Redefinition of Object#to_json
Redefinition of Object#to_json
Redefinition of Object#to_pretty_json
Redefinition of Object#to_pretty_json
Redefinition of Spectator::Double#to_s
Redefinition of Object#to_s
Redefinition of Object#try
Redefinition of Object#unsafe_as
Macros
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.