Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaximin committed Sep 11, 2023
1 parent 4660eaf commit 3ee6c1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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
Expand Down

0 comments on commit 3ee6c1e

Please sign in to comment.