diff --git a/README.md b/README.md index b900ebd..f24d6c3 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ expect(AwesomeJob).to have_enqueued_sidekiq_job(hash_excluding("bad_stuff" => an #### Testing scheduled jobs -*Use chainable matchers `#at` and `#in`* +*Use chainable matchers `#at`, `#in` and `#immediately`* ```ruby time = 5.minutes.from_now @@ -113,6 +113,13 @@ AwesomeJob.perform_in 5.minutes, 'Awesome', true expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).in(5.minutes) ``` +```ruby +# Job scheduled for a date in the past are enqueued immediately. +AwesomeJob.perform_later 5.minutes.ago, 'Awesome', true # equivalent to: AwesomeJob.perform_async 'Awesome', true +# test with... +expect(AwesomeJob).to have_enqueued_sidekiq_job('Awesome', true).immediately +``` + #### Testing queue set for job Use the chainable `#on` matcher diff --git a/lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb b/lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb index d505e01..32b29fc 100644 --- a/lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb +++ b/lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb @@ -56,7 +56,7 @@ def supports_block_expectations? # # Passes if a Job is enqueued as the result of a block. Chainable `with` # for arguments, `on` for queue, `at` for queued for a specific time, and - # `in` for a specific interval delay to being queued + # `in` for a specific interval delay to being queued, `immediately` for queued without delay. # # @example # @@ -79,6 +79,11 @@ def supports_block_expectations? # freeze_time do # expect { AwesomeJob.perform_in(1.hour) }.to enqueue_sidekiq_job.in(1.hour) # end + # + # # Without any delay + # expect { AwesomeJob.perform_async }.to enqueue_sidekiq_job.immediately + # expect { AwesomeJob.perform_at(1.hour.ago) }.to enqueue_sidekiq_job.immediately + def enqueue_sidekiq_job(job_class = nil) EnqueueSidekiqJob.new(job_class) end