Using apply to spy on a function