wspurgin / rspec-sidekiq

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

have_enqueued_sidekiq_job Diff is Wrong #162

Closed sshaw closed 11 months ago

sshaw commented 4 years ago
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.

cgunther commented 4 years ago

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"]]
Tolsee commented 3 years ago

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.

michaelfranzl commented 2 years ago

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]
stefanzero commented 1 year ago

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.