简体   繁体   中英

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

Use the inline support in your test:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM