Testing Jobs and Cables
Learn about job testing, and how to use job testing matchers and methods.
We'll cover the following
Rails provides minimal support for testing ActiveJob
background jobs and ActiveCable
web sockets.
Job testing matchers
In RSpec, a spec of type: :job
or one placed in the spec/jobs
directory exposes a couple of matchers. Before we run job specs, we need to specify that the jobs queue uses the test setting and not running off to Sidekiq
. We do that with ActiveJob::Base.queue_adapter = :test
, which we can use in a before
block.
The have_been_enqueued
matcher
The basic matcher is have_been_enqueued
, and the argument to it is the class of the job being enqueued, as in the following:
Get hands-on with 1400+ tech skills courses.