It is narrated from Sayyiduna Abdullah bin Umar (may Allah be pleased with them both) that the Messenger of Allah (peace and blessings be upon him) said: "Three men were walking when the rain overtook them. They took shelter in a cave in a mountain. Meanwhile a rock fell from the mountain and covered the mouth of the cave. They said to one another: 'Recall your best deeds and call upon Allah by them, so that because of them He may remove the rock from you.' One of them said: 'O Allah, my parents were elderly, and I also had a wife and children. I used to herd goats to provide for them. When I returned in the evening, I would give milk to my parents first of all. One day I went far off in search of trees, and when I returned they had both fallen asleep. I cleaned the vessel and milked into it. Then I stood with the milk at my parents' heads while my children were crying at my feet. I disliked to begin with them before my parents, and I disliked to wake them from their sleep. I kept standing until dawn broke. O Allah, You surely know that I did this only for Your pleasure, so remove this rock from us so that we may see the sky.' The rock moved and they saw the sky. The second said: 'O Allah, I had a cousin (my paternal uncle's daughter) whom I loved; she was the dearest of all people to me. I asked her to commit sin with me, and she said: "First bring me a hundred dinars." I strove and gathered a hundred dinars, then came to her. When I sat between her legs, she said: "Fear Allah, and do not break the seal except by its right (through marriage)." So I got up. O Allah, You know that I did this for Your pleasure, so remove this rock from us.' It moved a little more. The third said: 'O Allah, I hired a labourer for a faraq (a measure) of millet. When he finished his work, I offered him his wage, but he refused to take it and turned away from it. I kept working with that wage of his until I gathered from it cows and their herdsmen. That man came and said: "Fear Allah, give me my right and do not wrong me." I said: "Go and take these cows and their herdsmen." He said: "Fear Allah and do not mock me." I said: "I am not mocking you; go and take these cows and their herdsmen." He took them away. O Allah, You know that I did this for Your pleasure, so remove the rest of the rock as well.' Allah Almighty removed that rock too; then they came out and walked on."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب المساقاة / 11640