rspec-sidekiq
rspec-sidekiq copied to clipboard
have_enqueued_sidekiq_job Diff is Wrong
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 Array
s.
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"]]
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.
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]
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.