xeroshogun
xeroshogun

Reputation: 1092

Testing the result of Sidekiq background job with Rspec

I have a model method that sends info to a sidekiq background job. The background job changes some attributes on an object. I want to test to make sure this is happening as expected.

The Rspec test I wrote creates the object, then runs the method and expects the attribute to be changed. However, the attribute isn't changing and I suspect that the background job isn't running in the Rspec test. Anyone know how to make sidekiq process a job in the test so that it actually changes the attributes

Upvotes: 1

Views: 1360

Answers (1)

Mike Perham
Mike Perham

Reputation: 22238

Use the inline support in your test:

Sidekiq::Testing.inline! do
  model.do_something
end

Read more: https://github.com/mperham/sidekiq/wiki/Testing

Upvotes: 4

Related Questions