Recorded in the Ming-dynasty collection 《
精选雅笑》 (Selected Refined Jokes) by Yuzhang Zuiyuezi: people who insisted they would pass the imperial exam by quizzing fortune-tellers were said to be
白日做梦 — literally 'dreaming in broad daylight,' i.e. delusional about a sure thing.