wspurgin / rspec-sidekiq

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

Match on custom context #221

Open rubendinho opened 3 weeks ago

rubendinho commented 3 weeks ago

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 commented 2 weeks ago

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())