Rather than using a `Tempfile` and using a mock expectation, why not use a `StringIO` object and then you can verify the contents of it using `StringIO#string` after the fact?  That seems much simpler and less brittle.