Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 26, 2023

Conversation

wspurgin
Copy link
Owner

@wspurgin wspurgin commented Jul 26, 2023

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}
# 

@wspurgin wspurgin marked this pull request as ready for review July 26, 2023 16:48
@wspurgin wspurgin merged commit 4520dbd into main Jul 26, 2023
28 checks passed
@wspurgin wspurgin deleted the show_each_enqueued_job_on_its_own_line branch July 26, 2023 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant