How to I block a yahoo contact that is spamming me in Messages application?
There is no blocking mechanism built into iOS 6 and lower or on OS X. 

On iOS 7, you can add contacts to a block list and not receive calls, FaceTime, or messages from that contact (and the rest that you block).

From the settings app, use iMessage and FaceTime preferences to add numbers to a block list. 





On OS X or iOS before iOS 6, You will have to convince that person to stop sending messages or stop using that account.