Add captureStdout helper and mocks to some tests