@@ -351,9 +351,21 @@ def assert_no_performed_jobs(only: nil, except: nil, queue: nil, &block)
351
351
# assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
352
352
# end
353
353
#
354
+ # The +at+ and +args+ arguments also accept a proc.
354
355
#
355
- # The +args+ argument also accepts a proc which will get passed the actual
356
- # job's arguments. Your proc needs to return a boolean value determining if
356
+ # To the +at+ proc, it will get passed the actual job's at argument.
357
+ #
358
+ # def test_assert_enqueued_with
359
+ # expected_time = ->(at) do
360
+ # (Date.yesterday..Date.tomorrow).cover?(at)
361
+ # end
362
+ #
363
+ # MyJob.set(at: Date.today.noon).perform_later
364
+ # assert_enqueued_with(job: MyJob, at: expected_time)
365
+ # end
366
+ #
367
+ # To the +args+ proc, it will get passed the actual job's arguments
368
+ # Your proc needs to return a boolean value determining if
357
369
# the job's arguments matches your expectation. This is useful to check only
358
370
# for a subset of arguments.
359
371
#
@@ -366,7 +378,6 @@ def assert_no_performed_jobs(only: nil, except: nil, queue: nil, &block)
366
378
# assert_enqueued_with(job: MyJob, args: expected_args, queue: 'low')
367
379
# end
368
380
#
369
- #
370
381
# If a block is passed, asserts that the block will cause the job to be
371
382
# enqueued with the given arguments.
372
383
#
@@ -425,8 +436,21 @@ def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil)
425
436
# assert_performed_with(job: MyJob, at: Date.tomorrow.noon)
426
437
# end
427
438
#
428
- # The +args+ argument also accepts a proc which will get passed the actual
429
- # job's arguments. Your proc needs to return a boolean value determining if
439
+ # The +at+ and +args+ arguments also accept a proc.
440
+ #
441
+ # To the +at+ proc, it will get passed the actual job's at argument.
442
+ #
443
+ # def test_assert_enqueued_with
444
+ # expected_time = ->(at) do
445
+ # (Date.yesterday..Date.tomorrow).cover?(at)
446
+ # end
447
+ #
448
+ # MyJob.set(at: Date.today.noon).perform_later
449
+ # assert_enqueued_with(job: MyJob, at: expected_time)
450
+ # end
451
+ #
452
+ # To the +args+ proc, it will get passed the actual job's arguments
453
+ # Your proc needs to return a boolean value determining if
430
454
# the job's arguments matches your expectation. This is useful to check only
431
455
# for a subset of arguments.
432
456
#
@@ -630,7 +654,7 @@ def flush_enqueued_jobs(only: nil, except: nil, queue: nil)
630
654
631
655
def prepare_args_for_assertion ( args )
632
656
args . dup . tap do |arguments |
633
- if arguments [ :at ]
657
+ if arguments [ :at ] && ! arguments [ :at ] . respond_to? ( :call )
634
658
at_range = arguments [ :at ] - 1 ..arguments [ :at ] + 1
635
659
arguments [ :at ] = -> ( at ) { at_range . cover? ( at ) }
636
660
end
0 commit comments