From 7b2b285ba72e5cc05077c0dae8742b35f3e4b192 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 3 Aug 2016 12:19:36 +1000 Subject: [PATCH] Rescue spec fails within enqueue_job matcher Failing code tested by the enqueue_job matcher made it fail with: expected ConfirmOrderJob to be enqueued matching {} (??? others enqueued) That was not helpful and masking the real failure. That failure is now passed on. The hidden intermittent failure happened in 5% of runs on Travis. --- spec/support/delayed_job_helper.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/support/delayed_job_helper.rb b/spec/support/delayed_job_helper.rb index 82fd79c95a..84d03cc651 100644 --- a/spec/support/delayed_job_helper.rb +++ b/spec/support/delayed_job_helper.rb @@ -34,7 +34,12 @@ module OpenFoodNetwork match do |event_proc| last_job_id_before = Delayed::Job.last.andand.id || 0 - event_proc.call + begin + event_proc.call + rescue StandardError => e + @exception = e + raise e + end @jobs_created = Delayed::Job.where('id > ?', last_job_id_before) @@ -57,11 +62,11 @@ module OpenFoodNetwork end failure_message_for_should do |event_proc| - "expected #{klass} to be enqueued matching #{options.inspect} (#{@jobs_created.andand.count || '???'} others enqueued)" + @exception || "expected #{klass} to be enqueued matching #{options.inspect} (#{@jobs_created.count} others enqueued)" end failure_message_for_should_not do |event_proc| - "expected #{klass} to not be enqueued matching #{options.inspect}" + @exception || "expected #{klass} to not be enqueued matching #{options.inspect}" end end end