-
Notifications
You must be signed in to change notification settings - Fork 5
Doubles
Doubles are used as stand-in objects.
They provide a way to isolate components from each other in tests.
In general, doubles must be defined outside a test before they can be used.
To define a double, use the double
keyword, provide a name, and a block.
double :my_double do
# Stubs go here.
end
Then to use the double in a test, call double()
with the name of the double to use.
dbl = double(:my_double)
The methods that a double exposes must be defined ahead of time in the double
block.
This is done by using stubs.
Be sure to read the documentation on stubs for information on how to use them.
Additionally, there are some variants of doubles that have different properties. [Anonymous Doubles](Anonymous Doubles) can be used for quick stand-ins and don't require a full definition. [Verifying Doubles](Verifying Doubles) check that the type they stand-in for behave similarly. [Null objects](Null Objects) return nil for undefined methods.