This is a problem that has happened a few times in the last year. I will code something, spend hours doing it, get 100% code coverage, then find out it wasn't exactly what my employer wanted.
There have been times when its my fault because I didn't understand something clearly, and other times because my employer doesn't understand fully how his problem can/can't be solved by the way he thinks the code will work.
When I get the specs to code something, it's in an email, work chat, or via a text. What I've decided to do is before I start coding, create my own doc and share it with him, to make sure we are on the same page.
Here is an example of what I've tried to create, but it just seems messy.
Does anyone have a template or advice on how to write greats specs before you code?