Extract IO stubbing into test helper