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

Match on custom context #221

Open
rubendinho opened this issue Jun 8, 2024 · 1 comment · May be fixed by #222
Open

Match on custom context #221

rubendinho opened this issue Jun 8, 2024 · 1 comment · May be fixed by #222

Comments

@rubendinho
Copy link

Hello -

is there a way to match by context outside of the helpers provided? For example, I'd like to match by "retry"

Here's what I'm trying to do:

RSpec::Expectations::ExpectationNotMetError: expected to have an enqueued FooWorker job
  with arguments:
    -["conn_12wmsubtOLgh6Ekf9nUxti"]
  with context:
    -{ "queue" => :within_30_seconds }
but have enqueued only jobs
  -JID:f77048ad78065e9d3d8cd173 with arguments:
    -["conn_12wmsubtOLgh6Ekf9nUxti"]
   with context: { "retry" => 25, "queue" => "within_30_seconds", "backtrace" => false, "tags" => [], "class" => "FooWorker", "jid" => "f77048ad78065e9d3d8cd173", "created_at" => 1717873840.227412, "cattr" => { "sidekiq_queue" => "within_30_seconds", "sidekiq_tags" => [] }, "enqueued_at" => 1717873840.227484 }

Specifically, I'm trying to match by the cattr.sidekiq_queue. It would be nice to have something like:

expect(FooWorker).to have_enqueued_sidekiq_job(123).with(retry: 25)

@wspurgin
Copy link
Owner

Ah the Current Attributes middleware yes... There isn't a mechanism currently to just match anything directly against the context, but it should be fairly trivial to add.

In the end, you want something like this?

expect(FooWorker).to have_enqueued_sidekiq_job(123).with_context(cattr: hash_including("sidekiq_queue" => anything())

@wspurgin wspurgin linked a pull request Jun 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants