D O U B L E S ? • Pretend objects that stand in for real dependencies of the SUT. • In the literature, also referred to as mocks, stubs, fakes, spies, impostors, dummies, or other names depending on how they are used.
D O U B L E S ? • Within the context of RSpec::Mocks, these are distilled down to few underlying concepts: ! ! ! ! Object level: Test double Partial test double Method level: Method stub Message expectation
• Test double is a generic term for any object that stands in for a real object during a test (think "stunt double”). ! ! Note: The string argument is optional but recommended, because it is used in failure messages. • Once you have a test double, you can allow or expect messages on it… ! thingamajig = double(‘thingamajig’) Syntax
• A method stub is a method that we can program to return a predefined response during the execution of a test. ! allow(object).to receive(:message).and_return(value) Syntax
E C TAT I O N • A message expectation is a method stub that will raise an error if it is never called during the test. ! expect(object).to receive(:message) Syntax