The Holy Prophet (s.a.w.) has related:
“Three persons from the tribe of Bani Israel got together and started out on a journey. On the way, clouds gathered above them and it started to pour with rain and so they sought shelter in a nearby cave.
Suddenly, a large boulder slipped and blocked the entrance to the cave, trapping the three inside and transforming the day into a dark night for them. They had no other alternative except to turn to God for help.
“Let us use our sincere deeds as a means to obtain deliverance from this predicament,” suggested one of them.
All the others agreed with the suggestion.
One of them said, “O’ Lord! You are aware that I have an extremely attractive cousin and that I was infatuated and obsessed with her. One day, finding her alone, I took hold of her and wanted to satisfy my carnal desires, when she spoke out to me saying: O’ My cousin!Fear God and do not harm my chastity’. Hearing this, I crushed my lustful tendencies anddecided against the evil act. O’ Lord! If that deed of mine had been out of absolute sincerityand only for the purpose of acquiring Your pleasure, deliver us from grief and perdition.” Suddenly they witnessed that the huge boulder had moved away a little, faintly brightening up the interior of the cave.
The second person spoke out,“O’ Lord! You know that I had a father and a mother, so old that their bodies had bent over due to their excessive age, and that I used to tend to them regularly. One night, having brought them their food, I observed that both of them were asleep. I passed the entire night near them, the food in hand, without waking them up for fear of disturbing them. O’ Lord! If this deed of mine had been only for the sake of Your pleasure and happiness, open up a way for us and grant us salvation.”
As he completed his speech, the group noticed that the boulder had moved aside a little more.
The third person supplicated, “O’ Knower of every hidden and manifest! You know Yourself that I had a worker who used to work for me. When his term had reached its termination, I handed over to him his wages, but he was not pleased and desired more and, in a state of dissatisfaction and displeasure, he went away. I used his wage to purchase a goat, which I looked after separately and very soon I had a flock in my possession. After a period of time,the worker again approached me for his wage and I pointed towards the flock of sheep. Initially, he thought I was ridiculing him, but later, realizing my seriousness, took the entireflock and left.[30] O’ Lord! If this act had been prompted by sincerity and had only been for Your pleasure, deliver us from this quandary.”
At this point the entire boulder moved aside from the mouth of the cave and all three emerged from it, joyous and ecstatic, and continued their journey.[31]