Skip to content

enqueue_sidekiq_job RSpec block matcher for Sidekiq

License

Notifications You must be signed in to change notification settings

Uscreen-video/rspec-enqueue_sidekiq_job

Repository files navigation

enqueue_sidekiq_job RSpec block matcher

Installation

# Gemfile
group :test do
  gem 'rspec-enqueue_sidekiq_job'
end

Usage

Checks if a certain job was enqueued in a block.

expect { AwesomeWorker.perform_async }
  .to enqueue_sidekiq_job(AwesomeWorker)

Specifying arguments

expect { AwesomeWorker.perform_async(42, 'David')
  .to enqueue_sidekiq_job(AwesomeWorker).with(42, 'David')

Testing scheduled jobs

Use chainable matchers #at and #in:

time = 5.minutes.from_now
expect { AwesomeWorker.perform_at(time) }
  .to enqueue_sidekiq_job(AwesomeWorker).at(time)
interval = 5.minutes
expect { AwesomeWorker.perform_in(interval) }
  .to enqueue_sidekiq_job(AwesomeWorker).in(5.minutes)

Specifying counts

enqueue_sidekiq_job implies "exactly once" by default. But you can adjust that.

expect {
  2.times { AwesomeWorker.perform_async }
}.to enqueue_sidekiq_job(AwesomeWorker).twice
expect {
  3.times { AwesomeWorker.perform_async }
}.to enqueue_sidekiq_job(AwesomeWorker).exactly(3).times