wspurgin / rspec-sidekiq

RSpec for Sidekiq
https://github.com/wspurgin/rspec-sidekiq
Other
651 stars 133 forks source link

Update failure message to list out actual jobs line-by-line #195

Closed wspurgin closed 11 months ago

wspurgin commented 11 months ago

Should help in issues like #162 and #168 where the previous description made it harder to tell that the actual was an array of jobs with arguments, not a single job with a single array arg.

New description would look like:

SomeJob.perform_async "some_arg", "some_other_arg"

# Expectation accidentlly (or purposefully) expecting a single array arg
expect(SomeJob).to have_enqueued_sidekiq_job(["some_arg", "some_other_arg"])
#=> fails with message:
#
# expected to have an enqueued SomeJob job
#   with arguments:
#     -[["some_arg", "some_other_arg"]]
# but have enqueued only jobs
#   -JID:2b99eed860096f19c4b8df4d with arguments:
#     -["some_arg", "some_other_arg"]
# 

Closes #162 Closes #168

Also, it nests the "context" under each Job as well (formerly was "options" in the failure message - it's called the job hash "context" in Sidekiq, so I'm updating to use that terminology to be consistent).

The previous failure message only ever showed "at", but I've elected to include the full job context without args in the output. I'm doing that to pave the way for a general with_context (not tied to the name) matcher to tests things like "retry" and "queue" too.

As an example, if we added the in matcher:

SomeJob.perform_in 5.minutes, "some_arg", "some_other_arg"

# Expectation accidentlly (or purposefully) expecting a single array arg
expect(SomeJob).to have_enqueued_sidekiq_job(["some_arg", "some_other_arg"]).in(5.minutes)
#=> fails with message:
#
# expected to have an enqueued SomeJob job
#   with arguments:
#     -[["some_arg", "some_other_arg"]]
# but have enqueued only jobs
#   -JID:2b99eed860096f19c4b8df4d with arguments:
#     -["some_arg", "some_other_arg"]
#    with context:
#     -{"retry"=>true, "queue"=>"default", "class"=>"SomeJob", "at"=>1690385369.755574, "jid"=>"2b99eed860096f19c4b8df4d", "created_at"=>1690385069.755618}
#