With pepper spray, you have to be ready for it. If you're walking around with the spray in your hand, then you'd have a much better chance of repelling the attack. But how many hunters walk around with bear spray in their hands vs. how many walk around with a ready firearm?
You have to be ready in either case, gun or spray. How many people walk around with a gun at the ready? Maybe if you are a hunter and you are stalking and your gun is loaded and ready to shoot - cartridge in the chamber, safety off - then you are ready for a quick shot. Maybe. Is that situation the one that happens most? People are walking - maybe cutting through the brush from the road to the river to go salmon fishing or hiking with a pack on their back. They happen upon a bear. Or, as in the OP, you are in a tent at night. (In THAT scenario, where I don't have the luxury of running away, I'd like something that will put and end to the threat now and finally). Gun or spray - it doesn't matter - if the bear is close and charges, they may not get to bring either into action.
Pete