All these beautiful things are born from a man’s perceiving his own weakness. For from this, because of his longing for help, he turns to God with beseechings. And as he brings near his spirit unto God, He comes nigh unto him with His gifts. And He does not take away from him His inspiration, because of his great humility. For as a widow unto the judge, he cries at all times: avenge me on my adversary. Therefore God, the merciful, necessarily will delay his petitions, that he have the better reason to approach unto Him. And because of his need he will constantly remain at the fountain of help,... while God grants some of his demands quickly, others not: [He grants] those concerning which He knows that they are necessary for life, the rest He delays. And in some cases He withholds from him the ardour of his enemies, and in others He gives an opening to temptations, that this, as I have said, should be a cause for approaching unto God, and that he should become prudent by temptations. And this is what is said in the scripture: The Lord left many peoples and He did not destroy them at once, nor did He give them into the hand of Joshua, in order to test Israel by them so that the generations of the children of Israel should learn war.
Source: Mystic Treatises, Chapter 8