Next to spells in the PHB spell list are lists of components, some of which are material. When specified, material components are expended:
Components: V, S, M (gold dust worth at least 25 gp, which the spell consumes)
What I'm asking is exactly when those components are consumed. Is it when you cast the spell, or when you prepare it?