Tour · 17 of 25
A signature lists what a function touches, so a test can hand it a fake
A function that prints, sends mail, or reads the clock usually looks like any
other function: you learn what it touches by reading its body, and testing it
means patching globals or adding a mocking framework. In hd a public signature
lists what the function needs after $. $ Console says that remind_unpaid
writes to the console, and nothing else. The caller provides the console:
main passes on the real one, and the test uses $.with to put a recording
MemoryConsole in its place for one block, then reads what was written. A test
gets no real console at all, so a test that forgets the fake does not compile.
Your own traits work the same way: a Mailer, a Clock, a PaymentGateway.
Run: Ctrl+Enter · Pages: Alt+← Alt+→