I have never used pepper spray.
I used to use a good solid frame pump to swing at dogs. However, frame pumps are now a thing of the past. They are effective.
A good alternative is a water bottle. Every dog I have shot water at is clearly intimidated by the water and slows down or stops. It is more than enough to get away unscathed. Also, if my aim is errant, I am not riding into a toxic cloud. Water will not hurt me.
I did have one case where a dog jumped me near the top of a climb. He came up and was trying to figure out how to take a piece out of my spinning legs. I pulled out my water bottle and it was empty! So I threw the empty bottle in the dog's face. The dog swapped ends and took off like his tail was on fire. So I stopped and retrieved my bottle. The dog was off somewhere hiding and cowering. Ah the dreaded and feared water bottle.