God's ways are certainly not our ways.
At this point we may ask God, “Why do you permit such temptations? I was so close to being good!”
Italian priest Fr. Lorenzo Scupoli offered his explanation of why God permits temptations in his spiritual classic The Spiritual Combat. Scupoli writes, “We are by nature proud, ambitious, and ever mindful to the whims of our sense appetites. Hence it is that we are apt to flatter ourselves continually, and esteem ourselves out of all proportion to our merit. Such presumption is so great an obstacle to our spiritual progress, that the slightest taint of it impedes us in the attainment of true perfection.”
When God recognizes such pride, Scupoli explains, he permits a temptation to humble us and remind us of our need to rely on God. Scupoli gives the examples of Sts. Peter and Paul.
Did He not once rescue the erring Peter when He permitted that Apostle to deny Him, and forswear any knowledge of his Lord? Did He not grant to Peter self-knowledge and strength to cast aside his dangerous presumption? Did He not similarly deal with St. Paul when, in order to preserve him from this insidious vice and prevent him from making an improper use of the sublime revelations entrusted to him, He permitted a troublesome temptation to constantly remind the Apostle of his weakness?
In the end, God permits such temptations for our ultimate good. This does not mean that we should embrace the temptation, but that we should resist it with all of our strength, seeing it as a test of our faith in God. His ways are often mysterious and are certainly not our ways. God is able to bring a great amount of good from evil, the prime example being the crucifixion.
The key is to always remain humble in the sight of God, recognizing our own weaknesses and trusting firmly in God’s heavenly graces. God should be our rock and our strength in times of trial and while he may permit a strong temptation from the devil, he does so that we may progress along the path of perfection.