Desmodeus's avatar
Depends on the dog.
We had* one puppy that definitely knew where it was supposed to crap, but if I put him outside for an hour while I got ready to leave the house, the first thing he did when I let him back in was crap right in front of me... he'd then bolt because he knew there'd be trouble.
I have no understanding of why he did this, but do it he did.

*This is the only dog my family ever gave away because we couldn't handle it.
Lukky's avatar
Sounds like separation anxiety to me.

Dogs can pick up on your energy and they learn through repetition.
You would put him outside every time you were getting ready to leave. You probably anticipated that he would misbehave and he could sense that anxiety coming off of you.
So to him outside + anxiety from you = you leaving (scary)

So he was probably in a state of anxiety the whole time you were gone and couldn't relax to poop. 
So as soon as you came back and he could relax... poop. 
But then you'd get angry because of the poop and he'd know that anger = bad. 
So he'd run away. 

My point is that it's not spite.