rspec-sidekiq
rspec-sidekiq copied to clipboard
has_enqueued_sidekiq_job is not matching even though they are identical
expected to have an enqueued ApexChatEnrichmentJob job
arguments: [[{"data"=>{"chatId"=>"3078079", "chatAccountId"=>"3269891", "chatSummary"=>"Hello\\nBye", "chatTextFull"=>"Visitor: Bye\\nSystem: The chat session has ended.\\n", "provider"=>"Apex", "visitorId"=>"baca09be-79d7-46c2-81d3-0e12732f0244", "country"=>"USA"}, "eventTime"=>"2019-03-08 18:29:09", "eventType"=>"Chat", "platform"=>"USA", "scope"=>"CHAT", "scopeId"=>"172716", "subType"=>"Lead"}]]
found
arguments: [[{"data"=>{"chatId"=>"3078079", "chatAccountId"=>"3269891", "chatSummary"=>"Hello\\nBye", "chatTextFull"=>"Visitor: Bye\\nSystem: The chat session has ended.\\n", "provider"=>"Apex", "visitorId"=>"baca09be-79d7-46c2-81d3-0e12732f0244", "country"=>"USA"}, "eventTime"=>"2019-03-08 18:29:09", "eventType"=>"Chat", "platform"=>"USA", "scope"=>"CHAT", "scopeId"=>"172716", "subType"=>"Lead"}]]
Here is my spec
context 'when chat event is from Apex' do
let(:apex_chat_params) do
{
'country' => 'USA',
'data': {
'chatId' => '3078079',
'chatAccountId' => '3269891',
'chatSummary' => 'Hello\nBye',
'chatTextFull' => 'Visitor: Bye\nSystem: The chat session has ended.\n',
'provider' => 'Apex',
'visitorId' => 'baca09be-79d7-46c2-81d3-0e12732f0244'
},
'eventTime' => '2019-03-08 18:29:09',
'eventType' => 'Chat',
'scope' => 'CHAT',
'scopeId' => '172716',
'subType' => 'Lead'
}
end
it 'enqueues an ApexChatEnrichmentJob' do
post :create, params: apex_chat_params
expect(ApexChatEnrichmentJob).to have_enqueued_sidekiq_job([
data: {
chatId: '3078079',
chatAccountId: '3269891',
chatSummary: 'Hello\nBye',
chatTextFull: 'Visitor: Bye\nSystem: The chat session has ended.\n',
provider: 'Apex',
visitorId: 'baca09be-79d7-46c2-81d3-0e12732f0244',
country: 'USA'
},
eventTime: '2019-03-08 18:29:09',
eventType: 'Chat',
platform: 'USA',
scope: 'CHAT',
scopeId: '172716',
subType: 'Lead'
])
end
Any help would be appreciated
Having same issue in rspec-sidekiq 3.1.0. Tried both with have_enqueued_sidekiq_job([...]) and have_enqueued_sidekiq_job(...)
Same problem using 3.1.0.
expected to have an enqueued ProductWorker::CreateBatch job
arguments: [[{"tenant_id"=>1, "balance_id"=>1, "user_id"=>1, "readed_codes"=>["23131:1", "21312312:29"]}]]
found
arguments: [[{"tenant_id"=>1, "balance_id"=>1, "user_id"=>1, "readed_codes"=>["23131:1", "21312312:29"]}]]
This could be #162 where (at least) arrays are flattened in the "found arguments" output message, making you believe that the expectation is met, when in reality it isn't.
I ran into this too. The issue turned out to be that we sneakily had Sidekiq::Testing.inline! enabled in our tests. Disabling that fixed the issue.
I ran into the same issue: this is caused only when we use arrays on arguments.
Things we can do to avoid this issue is
- expect exactly what u need. don't add [] in the expectation. for example expect(User::RemoveAccess).to have_enqueued_sidekiq_job([user.id,user_account_ids]) here don't use [user.id, user_account_ids] use expect(User::RemoveAccess).to have_enqueued_sidekiq_job(user.id,user_account_ids) it will show the error as the same expectation when u use [ ] as @michaelfranzl mentioned.
as for me, this was the error, and I fixed using the same.
Another interesting issue I ran into, I had some Ruby code adding a Sidekiq job and two of the parameters were empty arrays.
Following this to the error message, you can see the use of the splat operator gets rid of them.
Now we don't have these job arguments structured well, which would def. save us here, but I wanted to point out something that made me scratch my head until I dived into the gem. If you do have empty arrays going into your parameters somehow, they will get excluded from the Failure message at the end.
I should probably obfuscate that URL, but it's non-production, so whatever, now you know my client...
The failure description definitely needs some work. Under the hood, rspec-sidekiq uses a ContainsExactly so the following are not the same expectations:
SomeJob.perform_async "some_arg", "some_other_arg"
# expect a job with two specific args
expect(SomeJob).to have_enqueued_sidekiq_job("some_arg", "some_other_arg")
# passes
# expect a job with _one_ array arg with two elements
expect(SomeJob).to have_enqueued_sidekiq_job(["some_arg", "some_other_arg"])
# fails
But the description, as pointed out, makes it a little hard to see that fact. I'll see if in V4 we can clean that up to make it more clear that a single array arg was expected and that was our failure