rspec-sidekiq icon indicating copy to clipboard operation
rspec-sidekiq copied to clipboard

have_enqueued_sidekiq_job Diff is Wrong

Open sshaw opened this issue 5 years ago • 4 comments

expect(Sidekiq::Worker).to have_enqueued_sidekiq_job('Foo', 'BarX')

Will fail with

     expected to have an enqueued Sidekiq::Worker job
         arguments: ["Foo", "BarX"]
     found
         arguments: [["Foo", "Bar"]]

Note that it presents an Array and an Array of Arrays.

sshaw avatar Jul 25 '19 03:07 sshaw

I believe this is correct. The "expected arguments" is showing you the arguments from your assertion in array form. The "found arguments" is showing you the arguments of all the jobs that are enqueued. The length of the outermost array is essentially the number of jobs enqueued. If you had multiple jobs enqueued the message would look like:

     expected to have an enqueued Sidekiq::Worker job
         arguments: ["Foo", "BarX"]
     found
         arguments: [["Foo", "Bar"], ["Foo", "Bar2"]]

cgunther avatar Apr 07 '20 18:04 cgunther

I encountered this when using Sidekiq::Client.enqueue_to_in.

The error message seems to show this message even when one of your arguments is an array.

expected to have an enqueued Sidekiq::Worker job
         arguments: ["Foo", "BarX"]
     found
         arguments: [["Foo", "Bar"]]

For example, if ["Foo", ["BarX"]] was the actual argument list, the above error would be shown.

Tolsee avatar May 25 '21 17:05 Tolsee

I have the same issue as @Tolsee . If I am passing an array as one of the arguments, that array is displayed flattened in the diff message. This is misleading in the sense that it reports two mismatches in the arguments, when in reality there is only one. See:

expected to have an enqueued MyJob job
  arguments: ["abc", [1, 2], 3]
found
  arguments: [["abc", 1, 2, 4]

michaelfranzl avatar Feb 03 '22 07:02 michaelfranzl

I had a similar problem, where the actual arguments were in a nested array. Upon careful inspection, I saw that I set one of the expected items incorrectly. After I fixed that argument, the test passed and it no longer displayed the nested array.

stefanzero avatar Jul 06 '22 18:07 stefanzero