The desorption of a carbon monoxide molecule from a Ru(0001) surface was studied by means of X-ray Absorption Spectra (XAS) computed with Transition Potential (TP-DFT) and Time Dependent (TD-DFT) DFT methods. By unraveling the evolution of the CO electronic structure upon desorption, we observed that at 2.3 Å from the surface, the CO molecule has already predominantly gas-phase character. While C 1s XAS is quite insensitive to changes in the C–O bond length, the O 1s excitation is very sensitive with the π* coming down in energy upon CO bond stretching, which competes with the increase in orbital energy due to the repulsive interaction with the metallic surface. We show in a systematic way that the TP-DFT method can describe the XAS rather well at the endpoints (chemisorbed and gas phase) but is affected by artificial charge transfer and/or incorrect spin treatment in the transition region in cases like CO, where there are low-lying π* orbitals and large exchange interactions between the core 1s and valence-acceptor π* orbitals. As an alternative, we demonstrate by comparing with experimental data that a linear response approach using TD-DFT employing common exchange-correlation functionals and finite-size clusters can yield a good description of the spectral evolution of the 1s → π* transition with correct spin and gas-to-chemisorbed chemical shifts in good agreement with experiment.