TWIL August 7th 2026

mockClass = instance_double(klass)
allow(klass).to receive(:new).and_return(mockClass)
allow(mockClass).to receive(:method)

It does fall apart a bit if multiple methods are called on the mocked instance though, since they can't be passed through. Each has to be mocked individually. Promotes testability I guess but if you're working in a complex legacy codebase...

Another banger from this series, and this time somewhat related to my usual areas of interest!